{"name":"node-stream-zip","version":"1.3.4","description":"node.js library for reading and extraction of ZIP archives","keywords":["zip","archive","unzip","stream"],"homepage":"https://github.com/antelle/node-stream-zip","author":{"name":"Antelle","email":"antelle.net@gmail.com","url":"https://github.com/antelle"},"bugs":{"url":"https://github.com/antelle/node-stream-zip/issues","email":"antelle.net@gmail.com"},"license":"MIT","files":["node_stream_zip.js"],"scripts":{"test":"nodeunit test/tests.js"},"main":"node_stream_zip.js","repository":{"type":"git","url":"git+https://github.com/antelle/node-stream-zip.git"},"engines":{"node":">=0.10.0"},"devDependencies":{"nodeunit":"^0.9.1"},"gitHead":"e94c5bb889c2ef9367708b53188f3568c1177480","_id":"node-stream-zip@1.3.4","_shasum":"15a24c094b01c77be9d8fbacc30c034cec25d772","_from":".","_npmVersion":"3.9.3","_nodeVersion":"6.2.1","_npmUser":{"name":"antelle","email":"antelle.net@gmail.com"},"dist":{"shasum":"15a24c094b01c77be9d8fbacc30c034cec25d772","tarball":"http://registry-npm.ywwl.com/node-stream-zip/download/node-stream-zip-1.3.4.tgz","integrity":"sha512-3jAXsCZ4c6utE48GK0L6C4ClMILk6bzMT7WGVR6RnHKDUsUwWlg/5uBvvSWe31N7uQRB389016Lg0yyZxYiP2Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCmIBcFAw3ui9Yoe8rmE7tw8g/cUURQS+gl5Y8UCf/glwIgbN9Jffc3eI/zvEATTgNkv2lxYMqBvySE4ls6PuUJx7Y="}],"size":7795,"noattachment":false,"key":"/node-stream-zip/-/node-stream-zip-1.3.4.tgz"},"maintainers":[{"name":"antelle","email":"antelle.net@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/node-stream-zip-1.3.4.tgz_1469221926129_0.6842776804696769"},"directories":{},"readme":"# node-stream-zip ![CI Checks](https://github.com/antelle/node-stream-zip/workflows/CI%20Checks/badge.svg)\n\nnode.js library for reading and extraction of ZIP archives.  \nFeatures:\n\n- it never loads entire archive into memory, everything is read by chunks\n- large archives support\n- all operations are non-blocking, no sync i/o\n- fast initialization\n- no dependencies, no binary addons\n- decompression with built-in zlib module\n- deflate, sfx, macosx/windows built-in archives\n- ZIP64 support\n\n## Installation\n\n```sh\nnpm i node-stream-zip\n```\n\n## Usage\n\nThere are two APIs provided:\n1. [promise-based / async](#async-api) \n2. [callbacks](#callback-api)\n\nIt's recommended to use the new, promise API, however the legacy callback API \nmay be more flexible for certain operations.\n\n### Async API\n\nOpen a zip file\n```javascript\nconst StreamZip = require('node-stream-zip');\nconst zip = new StreamZip.async({ file: 'archive.zip' });\n```\n\nStream one entry to stdout\n```javascript\nconst stm = await zip.stream('path/inside/zip.txt');\nstm.pipe(process.stdout);\nstm.on('end', () => zip.close());\n```\n\nRead a file as buffer\n```javascript\nconst data = await zip.entryData('path/inside/zip.txt');\nawait zip.close();\n```\n\nExtract one file to disk\n```javascript\nawait zip.extract('path/inside/zip.txt', './extracted.txt');\nawait zip.close();\n```\n\nList entries\n```javascript\nconst entriesCount = await zip.entriesCount;\nconsole.log(`Entries read: ${entriesCount}`);\n\nconst entries = await zip.entries();\nfor (const entry of Object.values(entries)) {\n    const desc = entry.isDirectory ? 'directory' : `${entry.size} bytes`;\n    console.log(`Entry ${entry.name}: ${desc}`);\n}\n\n// Do not forget to close the file once you're done\nawait zip.close();\n```\n\nExtract a folder from archive to disk\n```javascript\nfs.mkdirSync('extracted');\nawait zip.extract('path/inside/zip/', './extracted');\nawait zip.close();\n```\n\nExtract everything\n```javascript\nfs.mkdirSync('extracted');\nconst count = await zip.extract(null, './extracted');\nconsole.log(`Extracted ${count} entries`);\nawait zip.close();\n```\n\nWhen extracting a folder, you can listen to `extract` event\n```javascript\nzip.on('extract', (entry, file) => {\n    console.log(`Extracted ${entry.name} to ${file}`);\n});\n```\n\n`entry` event is generated for every entry during loading\n```javascript\nzip.on('entry', entry => {\n    // you can already stream this entry,\n    // without waiting until all entry descriptions are read (suitable for very large archives)\n    console.log(`Read entry ${entry.name}`);\n});\n```\n\n### Callback API\n\nOpen a zip file\n```javascript\nconst StreamZip = require('node-stream-zip');\nconst zip = new StreamZip({ file: 'archive.zip' });\n\n// Handle errors\nzip.on('error', err => { /*...*/ });\n```\n\nList entries\n```javascript\nzip.on('ready', () => {\n    console.log('Entries read: ' + zip.entriesCount);\n    for (const entry of Object.values(zip.entries())) {\n        const desc = entry.isDirectory ? 'directory' : `${entry.size} bytes`;\n        console.log(`Entry ${entry.name}: ${desc}`);\n    }\n    // Do not forget to close the file once you're done\n    zip.close();\n});\n```\n\nStream one entry to stdout\n```javascript\nzip.on('ready', () => {\n    zip.stream('path/inside/zip.txt', (err, stm) => {\n        stm.pipe(process.stdout);\n        stm.on('end', () => zip.close());\n    });\n});\n```\n\nExtract one file to disk\n```javascript\nzip.on('ready', () => {\n    zip.extract('path/inside/zip.txt', './extracted.txt', err => {\n        console.log(err ? 'Extract error' : 'Extracted');\n        zip.close();\n    });\n});\n```\n\nExtract a folder from archive to disk\n```javascript\nzip.on('ready', () => {\n    fs.mkdirSync('extracted');\n    zip.extract('path/inside/zip/', './extracted', err => {\n        console.log(err ? 'Extract error' : 'Extracted');\n        zip.close();\n    });\n});\n```\n\nExtract everything\n```javascript\nzip.on('ready', () => {\n    fs.mkdirSync('extracted');\n    zip.extract(null, './extracted', (err, count) => {\n        console.log(err ? 'Extract error' : `Extracted ${count} entries`);\n        zip.close();\n    });\n});\n```\n\nRead a file as buffer in sync way\n```javascript\nzip.on('ready', () => {\n    const data = zip.entryDataSync('path/inside/zip.txt');\n    zip.close();\n});\n```\n\nWhen extracting a folder, you can listen to `extract` event\n```javascript\nzip.on('extract', (entry, file) => {\n    console.log(`Extracted ${entry.name} to ${file}`);\n});\n```\n\n`entry` event is generated for every entry during loading\n```javascript\nzip.on('entry', entry => {\n    // you can already stream this entry,\n    // without waiting until all entry descriptions are read (suitable for very large archives)\n    console.log(`Read entry ${entry.name}`);\n});\n```\n\n## Options\n\nYou can pass these options to the constructor\n- `storeEntries: true` - you will be able to work with entries inside zip archive, otherwise the only way to access them is `entry` event\n- `skipEntryNameValidation: true` - by default, entry name is checked for malicious characters, like `../` or `c:\\123`, pass this flag to disable validation errors\n\n## Methods\n\n- `zip.entries()` - get all entries description\n- `zip.entry(name)` - get entry description by name\n- `zip.stream(entry, function(err, stm) { })` - get entry data reader stream\n- `zip.entryDataSync(entry)` - get entry data in sync way\n- `zip.close()` - cleanup after all entries have been read, streamed, extracted, and you don't need the archive\n\n## Building\n\nThe project doesn't require building. To run unit tests with [nodeunit](https://github.com/caolan/nodeunit):  \n```sh\nnpm test\n```\n\n## Known issues\n\n- [utf8](https://github.com/rubyzip/rubyzip/wiki/Files-with-non-ascii-filenames) file names\n\n## Out of scope\n\n- AES encrypted files: the library will throw an error if you try to open it\n\n## Contributors\n\nZIP parsing code has been partially forked from [cthackers/adm-zip](https://github.com/cthackers/adm-zip) (MIT license).\n","publish_time":1469221927734,"_cnpm_publish_time":1469221927734,"dist-tags":{"latest":"1.16.0"}}