node-stream-zip
node.js library for reading and extraction of ZIP archives.
Features:
- it never loads entire archive into memory, everything is read by chunks
- large archives support
- all operations are non-blocking, no sync i/o
- fast initialization
- no dependencies, no binary addons
- decompression with built-in zlib module
- deflate, deflate64, sfx, macosx/windows built-in archives
- ZIP64 support
Installation
$ npm install node-stream-zip
Usage
var StreamZip = require('node-stream-zip');
var zip = new StreamZip({
file: 'archive.zip',
storeEntries: true
});
zip.on('error', function(err) { });
zip.on('ready', function() {
console.log('Entries read: ' + zip.entriesCount);
zip.stream('node/benchmark/net/tcp-raw-c2s.js', function(err, stm) {
stm.pipe(process.stdout);
});
zip.extract('node/benchmark/net/tcp-raw-c2s.js', './temp/', function(err) {
console.log('Entry extracted');
});
zip.extract('node/benchmark/', './temp/', function(err, count) {
console.log('Extracted ' + count + ' entries');
});
zip.extract(null, './temp/', function(err, count) {
console.log('Extracted ' + count + ' entries');
});
var data = zip.entryDataSync('README.md');
});
zip.on('extract', function(entry, file) {
console.log('Extracted ' + entry.name + ' to ' + file);
});
zip.on('entry', function(entry) {
console.log('Read entry ', entry.name);
});
If you pass storeEntries: true
to constructor, you will be able to access entries inside zip archive with:
zip.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 way
Building
The project doesn't require building. To run unit tests with nodeunit:
$ npm test
Known issues
- utf8 file names
- AES encrypted files
Contributors
ZIP parsing code has been partially forked from cthackers/adm-zip (MIT license).