Comparing version 0.9.8 to 0.9.9
@@ -68,3 +68,5 @@ var Stream = require('stream'); | ||
) { | ||
self.cb(); | ||
var cb = self.cb; | ||
delete self.cb; | ||
cb(); | ||
} | ||
@@ -71,0 +73,0 @@ }); |
{ | ||
"name": "unzipper", | ||
"version": "0.9.8", | ||
"version": "0.9.9", | ||
"description": "Unzip cross-platform streaming API ", | ||
@@ -59,4 +59,4 @@ "author": "Evan Oxfeld <eoxfeld@gmail.com>", | ||
"scripts": { | ||
"test": "tap ./test/*.js" | ||
"test": "tap test --jobs=10 --coverage-report=html --no-browser" | ||
} | ||
} |
130
README.md
@@ -1,4 +0,18 @@ | ||
# unzipper [![Build Status](https://api.travis-ci.org/ZJONSSON/node-unzipper.png?branch=master)](https://travis-ci.org/ZJONSSON/node-unzipper?branch=master) | ||
[![NPM Version][npm-image]][npm-url] | ||
[![NPM Downloads][downloads-image]][downloads-url] | ||
[![Test Coverage][travis-image]][travis-url] | ||
[![Coverage][coverage-image]][coverage-url] | ||
This is a fork of [node-unzip](https://github.com/EvanOxfeld/node-unzip) which has not been maintained in a while. This fork addresses the following issues: | ||
[npm-image]: https://img.shields.io/npm/v/unzipper.svg | ||
[npm-url]: https://npmjs.org/package/unzipper | ||
[travis-image]: https://api.travis-ci.org/ZJONSSON/node-unzipper.png?branch=master | ||
[travis-url]: https://travis-ci.org/ZJONSSON/node-unzipper?branch=master | ||
[downloads-image]: https://img.shields.io/npm/dm/unzipper.svg | ||
[downloads-url]: https://npmjs.org/package/unzipper | ||
[coverage-image]: https://3tjjj5abqi.execute-api.us-east-1.amazonaws.com/prod/node-unzipper/badge | ||
[coverage-url]: https://3tjjj5abqi.execute-api.us-east-1.amazonaws.com/prod/node-unzipper/url | ||
# unzipper | ||
This is an active fork and drop-in replacement of the [node-unzip](https://github.com/EvanOxfeld/node-unzip) and addresses the following issues: | ||
* finish/close events are not always triggered, particular when the input stream is slower than the receivers | ||
@@ -30,3 +44,3 @@ * Any files are buffered into memory before passing on to entry | ||
Extract emits the 'close' event once the zip's contents have been fully extracted to disk. | ||
Extract emits the 'close' event once the zip's contents have been fully extracted to disk. Extract uses [fstream.Writer](https://www.npmjs.com/package/fstream) and therefore needs need an absolute path to the destination directory. This directory will be automatically created if it doesn't already exits. | ||
@@ -127,9 +141,10 @@ ### Parse zip file contents | ||
.pipe(unzipper.Parse()) | ||
.pipe(etl.map(entry => { | ||
if (entry.path == "this IS the file I'm looking for") | ||
entry | ||
.buffer() | ||
.then(content => fs.writeFile('output/path',content)) | ||
else | ||
.pipe(etl.map(async entry => { | ||
if (entry.path == "this IS the file I'm looking for") { | ||
const content = await entry.buffer(); | ||
await fs.writeFile('output/path',content); | ||
} | ||
else { | ||
entry.autodrain(); | ||
} | ||
})) | ||
@@ -164,12 +179,15 @@ ``` | ||
```js | ||
unzipper.Open.file('path/to/archive.zip') | ||
.then(function(d) { | ||
console.log('directory',d); | ||
return new Promise(function(resolve,reject) { | ||
d.files[0].stream() | ||
.pipe(fs.createWriteStream('firstFile')) | ||
.on('error',reject) | ||
.on('finish',resolve) | ||
}); | ||
async function main() { | ||
const directory = await unzipper.Open.file('path/to/archive.zip'); | ||
console.log('directory', d); | ||
return new Promise( (resolve, reject) => { | ||
directory.files[0] | ||
.stream() | ||
.pipe(fs.createWriteStream('firstFile')) | ||
.on('error',reject) | ||
.on('finish',resolve) | ||
}); | ||
} | ||
main(); | ||
``` | ||
@@ -186,12 +204,10 @@ | ||
unzipper.Open.url(request,'http://www2.census.gov/geo/tiger/TIGER2015/ZCTA5/tl_2015_us_zcta510.zip') | ||
.then(function(d) { | ||
var file = d.files.filter(function(d) { | ||
return d.path === 'tl_2015_us_zcta510.shp.iso.xml'; | ||
})[0]; | ||
return file.buffer(); | ||
}) | ||
.then(function(d) { | ||
console.log(d.toString()); | ||
}); | ||
async function main() { | ||
const directory = await unzipper.Open.url(request,'http://www2.census.gov/geo/tiger/TIGER2015/ZCTA5/tl_2015_us_zcta510.zip'); | ||
const file = directory.files.find(d => d.path === 'tl_2015_us_zcta510.shp.iso.xml'); | ||
const content = await file.buffer(); | ||
console.log(content.toString()); | ||
} | ||
main(); | ||
``` | ||
@@ -206,14 +222,15 @@ | ||
const googleStorageOptions = { | ||
url: `https://www.googleapis.com/storage/v1/b/m-bucket-name/o/my-object-name`, | ||
qs: { alt: 'media' }, | ||
jwt: { | ||
email: google.storage.credentials.client_email, | ||
key: google.storage.credentials.private_key, | ||
scopes: ['https://www.googleapis.com/auth/devstorage.read_only'] | ||
} | ||
url: `https://www.googleapis.com/storage/v1/b/m-bucket-name/o/my-object-name`, | ||
qs: { alt: 'media' }, | ||
jwt: { | ||
email: google.storage.credentials.client_email, | ||
key: google.storage.credentials.private_key, | ||
scopes: ['https://www.googleapis.com/auth/devstorage.read_only'] | ||
} | ||
}); | ||
return unzipper.Open.url(request, googleStorageOptions).then((zip) => { | ||
const file = zip.files.find((file) => file.path === 'my-filename'); | ||
return file.stream().pipe(res); | ||
async function getFile(req, res, next) { | ||
const directory = await unzipper.Open.url(request, googleStorageOptions); | ||
const file = zip.files.find((file) => file.path === 'my-filename'); | ||
return file.stream().pipe(res); | ||
}); | ||
@@ -232,12 +249,14 @@ ``` | ||
unzipper.Open.s3(s3Client,{Bucket: 'unzipper', Key: 'archive.zip'}) | ||
.then(function(d) { | ||
console.log('directory',d); | ||
return new Promise(function(resolve,reject) { | ||
d.files[0].stream() | ||
.pipe(fs.createWriteStream('firstFile')) | ||
.on('error',reject) | ||
.on('finish',resolve) | ||
}); | ||
async function main() { | ||
const directory = await unzipper.Open.s3(s3Client,{Bucket: 'unzipper', Key: 'archive.zip'}); | ||
return new Promise( (resolve, reject) => { | ||
directory.files[0] | ||
.stream() | ||
.pipe(fs.createWriteStream('firstFile')) | ||
.on('error',reject) | ||
.on('finish',resolve) | ||
}); | ||
} | ||
main(); | ||
``` | ||
@@ -254,12 +273,9 @@ | ||
unzipper.Open.buffer(buffer) | ||
.then(function(d) { | ||
console.log('directory',d); | ||
return new Promise(function(resolve,reject) { | ||
d.files[0].stream() | ||
.pipe(fs.createWriteStream('firstFile')) | ||
.on('error',reject) | ||
.on('finish',resolve) | ||
}); | ||
}); | ||
async function main() { | ||
const directory = await unzipper.Open.buffer(buffer); | ||
console.log('directory',directory); | ||
// ... | ||
} | ||
main(); | ||
``` | ||
@@ -266,0 +282,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41196
18
823
278