From 27f1e001668cc9d0615d5d4cf8049ffdc7c63488 Mon Sep 17 00:00:00 2001 From: Weslley Almeida Date: Wed, 13 Sep 2023 15:41:39 -0300 Subject: [PATCH] [FIX] ETXTBSY (#9) Issue because the promise ends before the file is unlocked --- src/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index cf4e495..84fbebd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -173,10 +173,11 @@ export default class YTDlpWrap { message: IncomingMessage, filePath: string ): Promise { + const file = fs.createWriteStream(filePath); return new Promise((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) ); });