Fixed fs write error.

This commit is contained in:
Felix Kaspar 2023-10-21 20:10:07 +02:00
parent 6248aa6a32
commit b5ba2b25cd

View File

@ -79,13 +79,21 @@ export async function oneToOne(wasmArray, snapshot) {
await checkExistsWithTimeout("/output.pdf", 1000); await checkExistsWithTimeout("/output.pdf", 1000);
console.log("Write started..."); 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 // TODO: Make this more elegant, this waits for the write to finish.
await new Promise((resolve, reject) => { // Maybe replace wasmfs with https://github.com/streamich/memfs
setTimeout(() => { let fileSize;
resolve(); while (true) {
}, 1000); 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?"); console.log("Could be done?");
fs.unlinkSync("input.pdf"); fs.unlinkSync("input.pdf");