Skip to content

Commit

Permalink
Actually wait to finish writing the file before resolving the promise
Browse files Browse the repository at this point in the history
awaiting `writeFileWithPromise` does not actually await writing the data
to a file. Fucking stupid bug, who hired me to work on this
  • Loading branch information
alichtman committed Jan 2, 2025
1 parent fc4cb46 commit 5dc66ad
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main/encryptionAndDecryptionLib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,13 @@ function writeFileWithPromise(path: string, data: Buffer): Promise<string> {
return new Promise((resolve, reject) => {
const stream = fs.createWriteStream(path, { flags: 'w+' });
stream.on('error', reject);
stream.write(data);
stream.write(data, (err) => {
if (err) {
reject('Failed to write');
} else {
resolve(path);
}
});
});
}

Expand Down

0 comments on commit 5dc66ad

Please sign in to comment.