Comparing version 0.9.1 to 0.9.2
var fs = require('fs'); | ||
var Promise = require('bluebird'); | ||
var directory = require('./directory'); | ||
var Stream = require('stream'); | ||
// Backwards compatibility for node versions < 8 | ||
if (!Stream.Writable || !Stream.Writable.prototype.destroy) | ||
Stream = require('readable-stream'); | ||
module.exports = { | ||
buffer: function(buffer) { | ||
var source = { | ||
stream: function(offset, length) { | ||
var stream = Stream.PassThrough(); | ||
stream.end(buffer.slice(offset, length)); | ||
return stream; | ||
}, | ||
size: function() { | ||
return Promise.resolve(buffer.length); | ||
} | ||
}; | ||
return directory(source); | ||
}, | ||
file: function(filename) { | ||
@@ -7,0 +25,0 @@ var source = { |
@@ -81,4 +81,6 @@ var util = require('util'); | ||
var entry = Stream.PassThrough(); | ||
var __autodraining = false; | ||
entry.autodrain = function() { | ||
__autodraining = true; | ||
return new Promise(function(resolve,reject) { | ||
@@ -133,3 +135,4 @@ entry.pipe(NoopStream()); | ||
var inflater = vars.compressionMethod ? zlib.createInflateRaw() : Stream.PassThrough(); | ||
entry.__autodraining = __autodraining; // expose __autodraining for test purposes | ||
var inflater = (vars.compressionMethod && !__autodraining) ? zlib.createInflateRaw() : Stream.PassThrough(); | ||
@@ -136,0 +139,0 @@ if (fileSizeKnown) { |
{ | ||
"name": "unzipper", | ||
"version": "0.9.1", | ||
"version": "0.9.2", | ||
"description": "Unzip cross-platform streaming API ", | ||
@@ -5,0 +5,0 @@ "author": "Evan Oxfeld <eoxfeld@gmail.com>", |
@@ -228,4 +228,24 @@ # unzipper [![Build Status](https://api.travis-ci.org/ZJONSSON/node-unzipper.png)](https://travis-ci.org/ZJONSSON/node-unzipper.svg?branch=master) | ||
### Open.buffer(buffer) | ||
If you already have the zip file in-memory as a buffer, you can open the contents directly. | ||
Example: | ||
```js | ||
// never use readFileSync - only used here to simplify the example | ||
var buffer = fs.readFileSync('path/to/arhive.zip'); | ||
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) | ||
}); | ||
}); | ||
``` | ||
## 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
37827
785
251