mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2024-12-21 19:08:24 +01:00
Fixed fs write error.
This commit is contained in:
parent
6248aa6a32
commit
b5ba2b25cd
@ -79,13 +79,21 @@ export async function oneToOne(wasmArray, snapshot) {
|
||||
await checkExistsWithTimeout("/output.pdf", 1000);
|
||||
console.log("Write started...");
|
||||
|
||||
// TODO: [Important] This fails for large PDFs. Need to a way to check if file write is definitely done.
|
||||
// We need to wait for the file write in memfs to finish in node for some reason
|
||||
await new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
// TODO: Make this more elegant, this waits for the write to finish.
|
||||
// Maybe replace wasmfs with https://github.com/streamich/memfs
|
||||
let fileSize;
|
||||
while (true) {
|
||||
fileSize = fs.statSync("/output.pdf").size;
|
||||
await new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, 50);
|
||||
});
|
||||
if(fileSize > 0 && fileSize == fs.statSync("/output.pdf").size) // Wait for file Size not changing anymore.
|
||||
break;
|
||||
}
|
||||
|
||||
console.log("Could be done?");
|
||||
|
||||
fs.unlinkSync("input.pdf");
|
||||
|
Loading…
Reference in New Issue
Block a user