1
0
Fork 0

Await finish of filestream so file is created for node16

pull/1266/head
Ferenc Hammerl 2022-12-14 15:57:48 +01:00
parent 1d61e5fb19
commit b9de68a590
2 changed files with 10 additions and 11 deletions

View File

@ -219,6 +219,14 @@ export class DownloadHttpClient {
fileDownloadPath: string
): Promise<void> => {
destinationStream.close()
// await until file is created at downloadpath
// wrap destinationStream's open event in promise
await new Promise<void>(resolve => {
destinationStream.on('close', resolve)
if (destinationStream.writableFinished) {
resolve()
}
});
await rmFile(fileDownloadPath)
destinationStream = fs.createWriteStream(fileDownloadPath)
}

View File

@ -270,15 +270,6 @@ export async function getFileSize(filePath: string): Promise<number> {
}
export async function rmFile(filePath: string): Promise<void> {
// TODO: find actual fix
// node 16 `CreateWriteStream` no longer creates a file
// download-http-client.ts#L151 no longer creates a file and we fail here
try {
await fs.stat(filePath)
} catch (e) {
// File does not exist
return
}
await fs.unlink(filePath)
}