Gathering detailed insights and metrics for node-stream-zip
Gathering detailed insights and metrics for node-stream-zip
Gathering detailed insights and metrics for node-stream-zip
Gathering detailed insights and metrics for node-stream-zip
node.js library for fast reading of large ZIPs
npm install node-stream-zip
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
448 Stars
151 Commits
63 Forks
11 Watching
1 Branches
13 Contributors
Updated on 08 Nov 2024
Minified
Minified + Gzipped
JavaScript (94.26%)
HTML (5.04%)
CSS (0.6%)
Makefile (0.1%)
Cumulative downloads
Total Downloads
Last day
-5.6%
407,380
Compared to previous day
Last week
-1.1%
2,257,115
Compared to previous week
Last month
-3.1%
9,950,100
Compared to previous month
Last year
45.3%
105,290,782
Compared to previous year
4
node.js library for reading and extraction of ZIP archives.
Features:
1npm i node-stream-zip
There are two APIs provided:
It's recommended to use the new, promise API, however the legacy callback API may be more flexible for certain operations.
Open a zip file
1const StreamZip = require('node-stream-zip'); 2const zip = new StreamZip.async({ file: 'archive.zip' });
Stream one entry to stdout
1const stm = await zip.stream('path/inside/zip.txt'); 2stm.pipe(process.stdout); 3stm.on('end', () => zip.close());
Read a file as buffer
1const data = await zip.entryData('path/inside/zip.txt'); 2await zip.close();
Extract one file to disk
1await zip.extract('path/inside/zip.txt', './extracted.txt'); 2await zip.close();
List entries
1const entriesCount = await zip.entriesCount; 2console.log(`Entries read: ${entriesCount}`); 3 4const entries = await zip.entries(); 5for (const entry of Object.values(entries)) { 6 const desc = entry.isDirectory ? 'directory' : `${entry.size} bytes`; 7 console.log(`Entry ${entry.name}: ${desc}`); 8} 9 10// Do not forget to close the file once you're done 11await zip.close();
Extract a folder from archive to disk
1fs.mkdirSync('extracted'); 2await zip.extract('path/inside/zip/', './extracted'); 3await zip.close();
Extract everything
1fs.mkdirSync('extracted'); 2const count = await zip.extract(null, './extracted'); 3console.log(`Extracted ${count} entries`); 4await zip.close();
When extracting a folder, you can listen to extract
event
1zip.on('extract', (entry, file) => { 2 console.log(`Extracted ${entry.name} to ${file}`); 3});
entry
event is generated for every entry during loading
1zip.on('entry', entry => { 2 // you can already stream this entry, 3 // without waiting until all entry descriptions are read (suitable for very large archives) 4 console.log(`Read entry ${entry.name}`); 5});
Open a zip file
1const StreamZip = require('node-stream-zip'); 2const zip = new StreamZip({ file: 'archive.zip' }); 3 4// Handle errors 5zip.on('error', err => { /*...*/ });
List entries
1zip.on('ready', () => { 2 console.log('Entries read: ' + zip.entriesCount); 3 for (const entry of Object.values(zip.entries())) { 4 const desc = entry.isDirectory ? 'directory' : `${entry.size} bytes`; 5 console.log(`Entry ${entry.name}: ${desc}`); 6 } 7 // Do not forget to close the file once you're done 8 zip.close(); 9});
Stream one entry to stdout
1zip.on('ready', () => { 2 zip.stream('path/inside/zip.txt', (err, stm) => { 3 stm.pipe(process.stdout); 4 stm.on('end', () => zip.close()); 5 }); 6});
Extract one file to disk
1zip.on('ready', () => { 2 zip.extract('path/inside/zip.txt', './extracted.txt', err => { 3 console.log(err ? 'Extract error' : 'Extracted'); 4 zip.close(); 5 }); 6});
Extract a folder from archive to disk
1zip.on('ready', () => { 2 fs.mkdirSync('extracted'); 3 zip.extract('path/inside/zip/', './extracted', err => { 4 console.log(err ? 'Extract error' : 'Extracted'); 5 zip.close(); 6 }); 7});
Extract everything
1zip.on('ready', () => { 2 fs.mkdirSync('extracted'); 3 zip.extract(null, './extracted', (err, count) => { 4 console.log(err ? 'Extract error' : `Extracted ${count} entries`); 5 zip.close(); 6 }); 7});
Read a file as buffer in sync way
1zip.on('ready', () => { 2 const data = zip.entryDataSync('path/inside/zip.txt'); 3 zip.close(); 4});
When extracting a folder, you can listen to extract
event
1zip.on('extract', (entry, file) => { 2 console.log(`Extracted ${entry.name} to ${file}`); 3});
entry
event is generated for every entry during loading
1zip.on('entry', entry => { 2 // you can already stream this entry, 3 // without waiting until all entry descriptions are read (suitable for very large archives) 4 console.log(`Read entry ${entry.name}`); 5});
You can pass these options to the constructor
storeEntries: true
- you will be able to work with entries inside zip archive, otherwise the only way to access them is entry
eventskipEntryNameValidation: true
- by default, entry name is checked for malicious characters, like ../
or c:\123
, pass this flag to disable validation errorsnameEncoding: 'utf8'
- encoding used to decode file names, UTF8 by defaultzip.entries()
- get all entries descriptionzip.entry(name)
- get entry description by namezip.stream(entry, function(err, stm) { })
- get entry data reader streamzip.entryDataSync(entry)
- get entry data in sync wayzip.close()
- cleanup after all entries have been read, streamed, extracted, and you don't need the archiveThe project doesn't require building. To run unit tests with nodeunit:
1npm test
ZIP parsing code has been partially forked from cthackers/adm-zip (MIT license).
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
binaries present in source code
Details
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 2/27 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
23 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
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