Installations
npm install unzip-stream
Releases
Unable to fetch releases
Developer
mhr3
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
No
Node Version
18.16.0
NPM Version
9.5.1
Statistics
78 Stars
141 Commits
30 Forks
2 Watching
3 Branches
1 Contributors
Updated on 06 Jun 2024
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
31,176,155
Last day
5.4%
41,519
Compared to previous day
Last week
3.4%
217,674
Compared to previous week
Last month
3.3%
898,815
Compared to previous month
Last year
53.8%
10,642,015
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
unzip-stream
Streaming cross-platform unzip tool written in node.js.
This package is based on unzip (and its fork unzipper) and provides simple APIs for parsing and extracting zip files. It uses new streaming engine which allows it to process also files which would fail with unzip. There are no added compiled dependencies - inflation is handled by node.js's built in zlib support.
Please note that the zip file format isn't really meant to be processed by streaming, though this library should succeed in most cases, if you do have complete zip file available, you should consider using other libraries which read zip files from the end - as originally intended (for example yauzl or decompress-zip).
Installation
1$ npm install unzip-stream
Quick Examples
Parse zip file contents
Process each zip file entry or pipe entries to another stream.
Important: If you do not intend to consume an entry stream's raw data, call autodrain() to dispose of the entry's contents. Otherwise the stream will get stuck.
1fs.createReadStream('path/to/archive.zip') 2 .pipe(unzip.Parse()) 3 .on('entry', function (entry) { 4 var filePath = entry.path; 5 var type = entry.type; // 'Directory' or 'File' 6 var size = entry.size; // might be undefined in some archives 7 if (filePath === "this IS the file I'm looking for") { 8 entry.pipe(fs.createWriteStream('output/path')); 9 } else { 10 entry.autodrain(); 11 } 12 });
Parse zip by piping entries downstream
If you pipe
from unzip-stream the downstream components will receive each entry
for further processing. This allows for clean pipelines transforming zipfiles into unzipped data.
Example using stream.Transform
:
1fs.createReadStream('path/to/archive.zip')
2 .pipe(unzip.Parse())
3 .pipe(stream.Transform({
4 objectMode: true,
5 transform: function(entry,e,cb) {
6 var filePath = entry.path;
7 var type = entry.type; // 'Directory' or 'File'
8 var size = entry.size;
9 if (filePath === "this IS the file I'm looking for") {
10 entry.pipe(fs.createWriteStream('output/path'))
11 .on('finish',cb);
12 } else {
13 entry.autodrain();
14 cb();
15 }
16 }
17 }
18 }));
Extract to a directory
1fs.createReadStream('path/to/archive.zip').pipe(unzip.Extract({ path: 'output/path' }));
Extract will emit the 'close' event when the archive is fully extracted, do NOT use the 'finish' event, which can be emitted before the writing finishes.
Extra options
The Parse
and Extract
methods allow passing an object with decodeString
property which will be used to decode non-utf8 file names in the archive. If not specified a fallback will be used.
1let parser = unzip.Parse({ decodeString: (buffer) => { return iconvLite.decode(buffer, 'iso-8859-2'); } }); 2input.pipe(parser).pipe(...);
Change history
- 0.3.0 - Added full support for Zip64
- 0.2.3 - Fix compatibility with node4
- 0.2.2 - Better handling of unicode file names
- 0.2.0 - Make Extract() emit 'close' only once all files are written
- 0.1.2 - Deal with non-zip64 files larger than 4GB
- 0.1.0 - Implemented new streaming engine
What's missing?
Currently ZIP files up to version 4.5 are supported (which includes Zip64 support - archives with 4GB+ files). There's no support for encrypted (password protected) zips, or symlinks.
Stable Version
The latest stable version of the package.
Stable Version
0.3.4
HIGH
1
7.5/10
Summary
unzip-stream allows Arbitrary File Write via artifact extraction
Affected Versions
< 0.3.2
Patched Versions
0.3.2
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 5/24 approved changesets -- score normalized to 2
Reason
0 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 12 are checked with a SAST tool
Score
3.3
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More