Comparing version 0.6.0 to 0.7.0
@@ -75,2 +75,3 @@ var util = require('util'); | ||
var entry = Stream.PassThrough(); | ||
entry.autodrain = function() { | ||
@@ -83,2 +84,20 @@ return new Promise(function(resolve,reject) { | ||
}; | ||
entry.buffer = function() { | ||
return new Promise(function(resolve,reject) { | ||
var buffer = new Buffer(''), | ||
bufferStream = Stream.Transform() | ||
.on('finish',function() { | ||
resolve(buffer); | ||
}) | ||
.on('error',reject); | ||
bufferStream._transform = function(d,e,cb) { | ||
buffer = Buffer.concat([buffer,d]); | ||
cb(); | ||
}; | ||
entry.pipe(bufferStream); | ||
}); | ||
}; | ||
entry.path = fileName; | ||
@@ -85,0 +104,0 @@ entry.props = {}; |
{ | ||
"name": "unzipper", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"description": "Unzip cross-platform streaming API ", | ||
@@ -5,0 +5,0 @@ "author": "Evan Oxfeld <eoxfeld@gmail.com>", |
@@ -106,3 +106,20 @@ # unzipper [![Build Status](https://api.travis-ci.org/ZJONSSON/node-unzipper.png)](https://api.travis-ci.org/ZJONSSON/node-unzipper) | ||
### Buffering the content of an entry into memory | ||
While the recommended strategy of consuming the unzipped contents is using streams, it is sometimes convenient to be able to get the full buffered contents of each file . Each `entry` provides a `.buffer` function that consumes the entry by buffering the contents into memory and returning a promise to the complete buffer. | ||
```js | ||
fs.createReadStream('path/to/archive.zip') | ||
.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 | ||
entry.autodrain(); | ||
})) | ||
## Licenses | ||
See LICENCE |
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
40568
29
605
124
8