From f31d689d826e32e3c65b39e573a4bca1227dfe3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Frinnstr=C3=B6m?= Date: Wed, 18 Nov 2020 20:28:38 +0100 Subject: [PATCH] Switch to using async fs operations --- .../src/reading/tree/ZipArchiveResponse.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/packages/backend-common/src/reading/tree/ZipArchiveResponse.ts b/packages/backend-common/src/reading/tree/ZipArchiveResponse.ts index 89f9803bd2..4106d49a11 100644 --- a/packages/backend-common/src/reading/tree/ZipArchiveResponse.ts +++ b/packages/backend-common/src/reading/tree/ZipArchiveResponse.ts @@ -132,18 +132,14 @@ export class ZipArchiveResponse implements ReadTreeResponse { await this.stream .pipe(unzipper.Parse()) - .on('entry', (entry: Entry) => { - if (this.shouldBeIncluded(entry)) { + .on('entry', async (entry: Entry) => { + // Ignore directory entries since we handle that with the file entries + // as a zip can have files with directories without directory entries + if (entry.type === 'File' && this.shouldBeIncluded(entry)) { const entryPath = this.getPath(entry); - if (entry.type === 'Directory') { - // Ignore directory entries since we handle that with the file entries - // since a zip can have files with directories without directory entries - entry.resume(); - return; - } const dirname = path.dirname(entryPath); if (dirname) { - fs.mkdirSync(path.join(dir, dirname), { recursive: true }); + await fs.mkdirp(path.join(dir, dirname)); } entry.pipe(fs.createWriteStream(path.join(dir, entryPath))); } else {