From cff60542f3d46ec780b3cd76dbecb1dba0d66e47 Mon Sep 17 00:00:00 2001 From: Ben Irvin Date: Tue, 16 Jan 2024 14:51:03 +0100 Subject: [PATCH] feat: add gzip support to readDir --- cli-tests/utils/fs.js | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/cli-tests/utils/fs.js b/cli-tests/utils/fs.js index ffbc27a7f7..70abf3cffc 100644 --- a/cli-tests/utils/fs.js +++ b/cli-tests/utils/fs.js @@ -158,27 +158,30 @@ const readDir = async (archive, dir) => { * @type {string[]} */ const files = []; + const isGzipped = archive.endsWith('.tar.gz'); await new Promise((resolve, reject) => { - pipeline( - [ - // Source: Archive stream - fs.createReadStream(archive), - // Transform: tar parser - new tar.Parse({ - // Match tar entry with the given filename - filter: (filePath, entry) => entry.type === 'File' && dir === path.dirname(filePath), - // Set outStream to - async onentry(entry) { - files.push(path.basename(entry.path)); + const streams = [fs.createReadStream(archive)]; + if (isGzipped) { + streams.push(zlib.createGunzip()); + } - // Consume the entry anyway to avoid blocking the tar parser - await rawCollector(entry); - }, - }), - ], - (err) => (err ? reject(err) : resolve()) + // Add the tar parser + streams.push( + new tar.Parse({ + // Match tar entry with the given filename + filter: (filePath, entry) => entry.type === 'File' && dir === path.dirname(filePath), + // Set outStream to + async onentry(entry) { + files.push(path.basename(entry.path)); + + // Consume the entry anyway to avoid blocking the tar parser + await rawCollector(entry); + }, + }) ); + + pipeline(streams, (err) => (err ? reject(err) : resolve())); }); return files;