Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/Open/directory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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 });
Expand Down
26 changes: 26 additions & 0 deletions test/open-extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});
Loading