diff --git a/src/internal/download-http-client.ts b/src/internal/download-http-client.ts index 2df4675..e365f3a 100644 --- a/src/internal/download-http-client.ts +++ b/src/internal/download-http-client.ts @@ -219,6 +219,13 @@ export class DownloadHttpClient { fileDownloadPath: string ): Promise => { destinationStream.close() + // await until file is created at downloadpath; node15 and up fs.createWriteStream had not created a file yet + await new Promise(resolve => { + destinationStream.on('close', resolve) + if (destinationStream.writableFinished) { + resolve() + } + }) await rmFile(fileDownloadPath) destinationStream = fs.createWriteStream(fileDownloadPath) }