Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fstream #133

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
21b1281
unzip uncompressed files
glebdmitriew Sep 26, 2014
58f7972
Add test case for uncompressed files
glebdmitriew Sep 26, 2014
bc20b60
updated package.json
glebdmitriew Sep 29, 2014
06a3ea4
updated description
glebdmitriew Sep 29, 2014
57d2905
updated version in package.json
glebdmitriew Sep 29, 2014
10c0c29
fix name
glebdmitriew Dec 3, 2014
991550f
issue #4 bugfix
binarybro Mar 20, 2015
9cac5fe
npm install unzip2
dvalentiate Mar 30, 2015
4c386d7
Added ability to override zlib options
sampsasaarela Mar 30, 2015
1170b44
v0.2.2
sampsasaarela Mar 30, 2015
f8f165a
Merge branch 'master' of github.com:dzire187/node-unzip-2
sampsasaarela Mar 30, 2015
ddde25f
Fixed name and pumbed v0.2.6
sampsasaarela Mar 30, 2015
a85b921
Updated fsstream
sampsasaarela May 5, 2016
b24e49a
v0.2.7
sampsasaarela May 5, 2016
bbed09b
fix unzip uncompressed blank files
dmitry-prohorov Jun 22, 2016
bd0f987
Merge pull request #16 from dmitry-prohorov/master
glebdmitriew Jun 22, 2016
a7e3044
Use most current version of fstream dependency
wvbe Aug 8, 2016
a16e0b9
Merge pull request #17 from wvbe/fstream-dependency-update
glebdmitriew Jan 22, 2018
45a588e
Merge pull request #6 from dvalentiate/master
glebdmitriew Jan 22, 2018
4af1bff
Merge pull request #5 from binarybro/patch-1
glebdmitriew Jan 22, 2018
d3ed2f0
Version bump
evertonfraga Feb 15, 2018
503c54d
Merge pull request #21 from evertonfraga/master
glebdmitriew Feb 20, 2018
fa9d2b0
Merge branch 'pr/7'
glebdmitriew Feb 20, 2018
9659d29
Fix name in package.json
glebdmitriew Feb 20, 2018
3702bce
Fix name in Readme
glebdmitriew Feb 20, 2018
ba603ce
Update package.json
markhowardrm May 16, 2019
ce4da15
Merge pull request #26 from markhowardrm/master
glebdmitriew May 16, 2019
4868474
Update package.json
markhowardrm May 16, 2019
bcb8887
Merge pull request #27 from markhowardrm/master
glebdmitriew May 16, 2019
b628894
fix in fstream version
victorLessa Aug 31, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# unzip [![Build Status](https://travis-ci.org/nearinfinity/node-unzip.png)](https://travis-ci.org/nearinfinity/node-unzip)
# node-unzip-2

Streaming cross-platform unzip tool written in node.js.
Streaming cross-platform unzip tool written in node.js.
It is an improved version of [Evan Oxfeld's node-unzip](https://github.com/isaacs/node-tar), which supports unzipping for files with a "STORE" compression (uncompressed files).

Unzip provides simple APIs similar to [node-tar](https://github.com/isaacs/node-tar) for parsing and extracting zip files.
There are no added compiled dependencies - inflation is handled by node.js's built in zlib support. Unzip is also an
Expand All @@ -9,7 +10,7 @@ example use case of [node-pullstream](https://github.com/nearinfinity/node-pulls
## Installation

```bash
$ npm install unzip
$ npm install node-unzip-2
```

## Quick Examples
Expand Down
40 changes: 30 additions & 10 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Parse.prototype._readFile = function () {
if (err) {
return self.emit('error', err);
}
if (vars.compressionMethod === 0) {
if (entry.type === 'Directory') {
self._pullStream.pull(vars.compressedSize, function (err, compressedData) {
if (err) {
return self.emit('error', err);
Expand All @@ -132,17 +132,32 @@ Parse.prototype._readFile = function () {
});
} else {
var fileSizeKnown = !(vars.flags & 0x08);
var has_compression = !(vars.compressionMethod === 0);
var inflater;

var inflater = zlib.createInflateRaw();
inflater.on('error', function (err) {
self.emit('error', err);
});
if(has_compression) {
inflater = zlib.createInflateRaw(self._opts.zlibOptions || {});
inflater.on('error', function (err) {
self.emit('error', err);
});
}

if (fileSizeKnown) {
entry.size = vars.uncompressedSize;
if (hasEntryListener) {
entry.on('finish', self._readRecord.bind(self));
self._pullStream.pipe(vars.compressedSize, inflater).pipe(entry);
if(has_compression) {
self._pullStream.pipe(vars.compressedSize, inflater).pipe(entry);
} else {
self._pullStream.pull(vars.compressedSize, function (err, compressedData) {
if (err) {
return self.emit('error', err);
}

entry.write(compressedData);
entry.end();
});
}
} else {
self._pullStream.drain(vars.compressedSize, function (err) {
if (err) {
Expand All @@ -162,17 +177,21 @@ Parse.prototype._readFile = function () {
}
this.push(buf);
}
self._pullStream.unpipe();
self._pullStream.prepend(extra);
setImmediate(function() {
self._pullStream.unpipe();
self._pullStream.prepend(extra);
self._processDataDescriptor(entry);
});
return this.push(null);
});

self._pullStream.pipe(matchStream);
if (hasEntryListener) {
matchStream.pipe(inflater).pipe(entry);
if(has_compression) {
matchStream.pipe(inflater).pipe(entry);
} else {
matchStream.pipe(entry);
}
}
}
}
Expand Down Expand Up @@ -304,8 +323,9 @@ Parse.prototype._flush = function (callback) {
return setImmediate(this._flush.bind(this, callback));
}

var r = callback();
this.emit('close');
return callback();
return r;
};

Parse.prototype.addListener = function(type, listener) {
Expand Down
28 changes: 12 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
{
"name": "unzip",
"version": "0.1.9",
"name": "node-unzip-2",
"version": "0.2.8",
"description": "Unzip cross-platform streaming API compatible with fstream and fs.ReadStream",
"author": "Evan Oxfeld <evan.oxfeld@nearinfinity.com>",
"author": "Hlib Dmytriiev <glebdmitriew@gmail.com>",
"maintainers": [
{
"name": "Evan Oxfeld",
"email": "[email protected]"
},
{
"name": "Joe Ferner",
"email": "[email protected]"
}
"Hlib Dmytriiev <[email protected]>"
],
"repository": {
"type": "git",
"url": "https://github.com/nearinfinity/node-unzip.git"
"url": "https://github.com/glebdmitriew/node-unzip-2.git"
},
"license": "MIT",
"dependencies": {
"fstream": "~0.1.21",
"fstream": "^1.0.12",
"pullstream": "~0.4.0",
"binary": "~0.3.0",
"readable-stream": "~1.0.0",
Expand All @@ -33,7 +26,6 @@
"stream-buffers": "~0.2.3"
},
"directories": {
"example": "examples",
"test": "test"
},
"keywords": [
Expand All @@ -47,6 +39,10 @@
],
"main": "unzip.js",
"scripts": {
"test": "./node_modules/.bin/tap ./test/*.js"
}
"test": "tap ./test/*.js"
},
"bugs": {
"url": "https://github.com/glebdmitriew/node-unzip-2/issues"
},
"homepage": "https://github.com/glebdmitriew/node-unzip-2"
}
42 changes: 42 additions & 0 deletions test/uncompressed.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,46 @@ test("extract uncompressed archive", function (t) {
});
}
});
});

test("parse really uncompressed archive", function (t) {
var archive = path.join(__dirname, '../testData/uncompressed/lorem.zip');

var unzipParser = unzip.Parse();
fs.createReadStream(archive).pipe(unzipParser);
unzipParser.on('error', function(err) {
throw err;
});

unzipParser.on('close', t.end.bind(this));
});

test("extract really uncompressed archive", function (t) {
var archive = path.join(__dirname, '../testData/uncompressed/lorem.zip');

temp.mkdir('node-unzip-', function (err, dirPath) {
if (err) {
throw err;
}
console.log(dirPath);
var unzipExtractor = unzip.Extract({ path: dirPath });
unzipExtractor.on('error', function(err) {
throw err;
});
unzipExtractor.on('close', testExtractionResults);

fs.createReadStream(archive).pipe(unzipExtractor);

function testExtractionResults() {
dirdiff(path.join(__dirname, '../testData/uncompressed/lorem_unziped'), dirPath, {
fileContents: true
}, function (err, diffs) {
if (err) {
throw err;
}
t.equal(diffs.length, 0, 'extracted directory contents');
t.end();
});
}
});
});
Binary file added testData/uncompressed/lorem.zip
Binary file not shown.
Loading