Await finish of filestream so file is created for node16

This commit is contained in:
Ferenc Hammerl committed 2022-12-14 15:57:48 +01:00
1 parent 98e1a30696
commit d6c0a88eeb
2 files changed
+8 -9

No files matched your search

+8
View File
@@ -219,6 +219,14 @@ export class DownloadHttpClient {
fileDownloadPath: string fileDownloadPath: string
): Promise<void> => { ): Promise<void> => {
destinationStream.close() 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) await rmFile(fileDownloadPath)
destinationStream = fs.createWriteStream(fileDownloadPath) destinationStream = fs.createWriteStream(fileDownloadPath)
} }
-9
View File
@@ -270,15 +270,6 @@ export async function getFileSize(filePath: string): Promise<number> {
} }
export async function rmFile(filePath: string): Promise<void> { 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) await fs.unlink(filePath)
} }