From 887566585ff147c406e285d886d7607491f0daf8 Mon Sep 17 00:00:00 2001 From: Rich Hodgkins Date: Mon, 16 Jun 2025 16:46:25 +0100 Subject: [PATCH] Support for progress option with extract --- lib/Open/directory.js | 6 +++++- test/open-extract.js | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/Open/directory.js b/lib/Open/directory.js index b45059e..b417f89 100644 --- a/lib/Open/directory.js +++ b/lib/Open/directory.js @@ -164,6 +164,7 @@ module.exports = function centralDirectory(source, options) { if (entry.type == 'Directory') { await fs.ensureDir(extractPath); + if (opts.progress) opts.progress(entry); return; } @@ -175,7 +176,10 @@ module.exports = function centralDirectory(source, options) { entry.stream(opts.password) .on('error', reject) .pipe(writer) - .on('close', resolve) + .on('close', () => { + if (opts.progress) opts.progress(entry); + resolve(); + }) .on('error', reject); }); }, { concurrency: opts.concurrency > 1 ? opts.concurrency : 1 }); diff --git a/test/open-extract.js b/test/open-extract.js index a184338..23d2559 100644 --- a/test/open-extract.js +++ b/test/open-extract.js @@ -36,4 +36,30 @@ test("extract compressed archive with open.file.extract", function (t) { }); }); }); +}); + +test("extraction progress with open.file.extract", function (t) { + const archive = path.join(__dirname, '../testData/compressed-standard/archive.zip'); + + temp.mkdir('node-unzip-2', function (err, dirPath) { + if (err) { + throw err; + } + const progressEntries = new Set(); + const progress = entry => { + progressEntries.add(entry.path); + }; + unzip.Open.file(archive) + .then(function(d) { + return d.extract({path: dirPath, progress}); + }) + .then(async function() { + const root = path.resolve(__dirname, '../testData/compressed-standard/inflated'); + // Check each entry exists + for (const p of progressEntries) { + t.ok(fs.pathExistsSync(path.join(root, p)), `progress entry does not exist: ${p}`); + } + t.end(); + }); + }); }); \ No newline at end of file