Skip to content

Commit

Permalink
[FIX] ETXTBSY (#9)
Browse files Browse the repository at this point in the history
Issue because the promise ends before the file is unlocked
  • Loading branch information
weslley75 authored Sep 13, 2023
1 parent 9a3e49f commit 27f1e00
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,11 @@ export default class YTDlpWrap {
message: IncomingMessage,
filePath: string
): Promise<IncomingMessage> {
const file = fs.createWriteStream(filePath);
return new Promise<IncomingMessage>((resolve, reject) => {
message.pipe(fs.createWriteStream(filePath));
message.pipe(file);
message.on('error', (e) => reject(e));
message.on('end', () =>
file.on('finish', () =>
message.statusCode == 200 ? resolve(message) : reject(message)
);
});
Expand Down

0 comments on commit 27f1e00

Please sign in to comment.