Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

unzipper

Package Overview
Dependencies
Maintainers
1
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unzipper - npm Package Compare versions

Comparing version 0.3.2 to 0.4.0

12

lib/extract.js

@@ -1,3 +0,1 @@

'use strict';
module.exports = Extract;

@@ -16,5 +14,7 @@

Parse.call(this);
var self = this;
this.on('entry', entry => {
Parse.call(self);
self.on('entry', function(entry) {
if (entry.type == 'Directory') return;

@@ -24,4 +24,6 @@ entry.pipe(Writer({

}))
.on('error',e => this.emit('error',e));
.on('error',function(e) {
self.emit('error',e);
});
});
}

@@ -5,12 +5,19 @@ var util = require('util');

var binary = require('binary');
var Promise = require('bluebird');
var PullStream = require('./PullStream');
// Backwards compatibility for node 0.8
if (!Stream.Writable)
Stream = require('readable-stream');
function noopStream() {
return Stream.Transform({
transform: (d,e,cb) => cb()
});
function NoopStream() {
if (!(this instanceof NoopStream)) {
return new NoopStream();
}
Stream.Transform.call(this);
}
util.inherits(NoopStream,Stream.Transform);
NoopStream.prototype._transform = function(d,e,cb) { cb() ;};
function Parse(opts) {

@@ -20,8 +27,10 @@ if (!(this instanceof Parse)) {

}
var self = this;
self._opts = opts || { verbose: false };
this._opts = opts || { verbose: false };
PullStream.call(this, this._opts);
this.on('finish',() => this.emit('close')) ;
this._readRecord();
PullStream.call(self, self._opts);
self.on('finish',function() {
self.emit('close');
});
self._readRecord();
}

@@ -32,3 +41,4 @@

Parse.prototype._readRecord = function () {
this.pull(4).then(data => {
var self = this;
self.pull(4).then(function(data) {
if (data.length === 0)

@@ -39,9 +49,9 @@ return;

if (signature === 0x04034b50)
this._readFile();
self._readFile();
else if (signature === 0x02014b50)
this._readCentralDirectoryFileHeader();
self._readCentralDirectoryFileHeader();
else if (signature === 0x06054b50)
this._readEndOfCentralDirectoryRecord();
self._readEndOfCentralDirectoryRecord();
else
this.emit('error', Error('invalid signature: 0x' + signature.toString(16)));
self.emit('error', Error('invalid signature: 0x' + signature.toString(16)));
});

@@ -51,3 +61,4 @@ };

Parse.prototype._readFile = function () {
this.pull(26).then(data => {
var self = this;
self.pull(26).then(function(data) {
var vars = binary.parse(data)

@@ -66,10 +77,12 @@ .word16lu('versionsNeededToExtract')

return this.pull(vars.fileNameLength).then(fileName => {
return self.pull(vars.fileNameLength).then(function(fileName) {
fileName = fileName.toString('utf8');
var entry = Stream.PassThrough();
entry.autodrain = () => new Promise( (resolve,reject) => {
entry.pipe(noopStream());
entry.on('finish',resolve);
entry.on('error',reject);
});
entry.autodrain = function() {
return new Promise(function(resolve,reject) {
entry.pipe(NoopStream());
entry.on('finish',resolve);
entry.on('error',reject);
});
};
entry.path = fileName;

@@ -80,3 +93,3 @@ entry.props = {};

if (this._opts.verbose) {
if (self._opts.verbose) {
if (entry.type === 'Directory') {

@@ -93,5 +106,5 @@ console.log(' creating:', fileName);

this.emit('entry', entry);
self.emit('entry', entry);
this.pull(vars.extraFieldLength).then(extraField => {
self.pull(vars.extraFieldLength).then(function(extraField) {
var fileSizeKnown = !(vars.flags & 0x08),

@@ -101,4 +114,4 @@ eof;

var inflater = vars.compressionMethod ? zlib.createInflateRaw() : Stream.PassThrough();
if (!this.listenerCount('entry'))
inflater = noopStream();
if (self.listenerCount && !self.listenerCount('entry'))
inflater = NoopStream();

@@ -113,7 +126,9 @@ if (fileSizeKnown) {

this.stream(eof)
self.stream(eof)
.pipe(inflater)
.on('error', e => this.emit('error',err))
.on('error',function(err) { self.emit('error',err);})
.pipe(entry)
.on('finish', () => fileSizeKnown ? this._readRecord() : this._processDataDescriptor(entry));
.on('finish', function() {
return fileSizeKnown ? self._readRecord() : self._processDataDescriptor(entry);
});
});

@@ -125,3 +140,4 @@ });

Parse.prototype._processDataDescriptor = function (entry) {
this.pull(16).then(data => {
var self = this;
self.pull(16).then(function(data) {
var vars = binary.parse(data)

@@ -135,3 +151,3 @@ .word32lu('dataDescriptorSignature')

entry.size = vars.uncompressedSize;
this._readRecord();
self._readRecord();
});

@@ -141,3 +157,4 @@ };

Parse.prototype._readCentralDirectoryFileHeader = function () {
this.pull(42).then(data => {
var self = this;
self.pull(42).then(function(data) {

@@ -163,9 +180,9 @@ var vars = binary.parse(data)

return this.pull(vars.fileNameLength).then(fileName => {
return self.pull(vars.fileNameLength).then(function(fileName) {
fileName = fileName.toString('utf8');
this.pull(vars.extraFieldLength).then(extraField => {
this.pull(vars.fileCommentLength).then(fileComment => {
return this._readRecord();
self.pull(vars.extraFieldLength).then(function(extraField) {
self.pull(vars.fileCommentLength).then(function(fileComment) {
return self._readRecord();
});

@@ -178,3 +195,4 @@ });

Parse.prototype._readEndOfCentralDirectoryRecord = function () {
this.pull(18).then(data => {
var self = this;
self.pull(18).then(function(data) {

@@ -192,8 +210,8 @@ var vars = binary.parse(data)

if (vars.commentLength) {
this.pull(vars.commentLength).then(comment => {
self.pull(vars.commentLength).then(function(comment) {
comment = comment.toString('utf8');
return this.end();
return self.end();
});
} else {
this.end();
self.end();
}

@@ -200,0 +218,0 @@ });

@@ -1,7 +0,10 @@

'use strict';
const Stream = require('stream');
const Promise = require('bluebird');
const util = require('util')
const Buffer = require('buffer').Buffer;
var Stream = require('stream');
var Promise = require('bluebird');
var util = require('util');
var Buffer = require('buffer').Buffer;
// Backwards compatibility for node 0.8
if (!Stream.Writable)
Stream = require('readable-stream');
function PullStream() {

@@ -11,7 +14,7 @@ if (!(this instanceof PullStream))

Stream.Duplex.call(this,{decodeStrings:false});
Stream.Writable.call(this,{decodeStrings:false});
this.buffer = new Buffer('');
}
util.inherits(PullStream,Stream.Duplex);
util.inherits(PullStream,Stream.Writable);

@@ -44,22 +47,22 @@ PullStream.prototype._write = function(chunk,e,cb) {

PullStream.prototype.stream = function(eof) {
const p = Stream.PassThrough();
let count = 0,done,packet;
var p = Stream.PassThrough();
var count = 0,done,packet,self= this;
const pull = () => {
if (this.buffer && this.buffer.length) {
function pull() {
if (self.buffer && self.buffer.length) {
if (typeof eof === 'number') {
packet = this.buffer.slice(0,eof);
this.buffer = this.buffer.slice(eof);
packet = self.buffer.slice(0,eof);
self.buffer = self.buffer.slice(eof);
eof -= packet.length;
done = !eof;
} else {
let match = this.buffer.indexOf(eof);
var match = self.buffer.indexOf(eof);
if (match !== -1) {
packet = this.buffer.slice(0,match);
this.buffer = this.buffer.slice(match);
packet = self.buffer.slice(0,match);
self.buffer = self.buffer.slice(match);
done = true;
} else {
let len = this.buffer.length - eof.length;
packet = this.buffer.slice(0,len);
this.buffer = this.buffer.slice(len);
var len = self.buffer.length - eof.length;
packet = self.buffer.slice(0,len);
self.buffer = self.buffer.slice(len);
}

@@ -71,17 +74,17 @@ }

if (!done) {
if (this.flushcb) {
this.removeListener('chunk',pull);
this.emit('error','FILE_ENDED');
if (self.flushcb) {
self.removeListener('chunk',pull);
self.emit('error','FILE_ENDED');
p.emit('error','FILE_ENDED');
}
this.next();
self.next();
} else {
this.removeListener('chunk',pull);
if (!this.buffer.length)
this.next();
self.removeListener('chunk',pull);
if (!self.buffer.length)
self.next();
p.end();
}
};
}
this.on('chunk',pull);
self.on('chunk',pull);
pull();

@@ -92,13 +95,15 @@ return p;

PullStream.prototype.pull = function(len) {
let buffer = new Buffer('');
var buffer = new Buffer(''),
self = this;
var concatStream = Stream.Transform();
concatStream._transform = function(d,e,cb) {
buffer = Buffer.concat([buffer,d]);
cb();
};
return new Promise( (resolve,reject) => {
this.stream(len)
.pipe(Stream.Transform({
transform: (d,e,cb) => {
buffer = Buffer.concat([buffer,d]);
cb();
}
}))
.on('finish',() => resolve(buffer))
return new Promise(function(resolve,reject) {
self.stream(len)
.pipe(concatStream)
.on('finish',function() {resolve(buffer);})
.on('error',reject);

@@ -105,0 +110,0 @@ });

{
"name": "unzipper",
"version": "0.3.2",
"version": "0.4.0",
"description": "Unzip cross-platform streaming API ",

@@ -27,4 +27,8 @@ "author": "Evan Oxfeld <eoxfeld@gmail.com>",

"binary": "~0.3.0",
"bluebird": "^3.4.1",
"fstream": "~1.0.10"
"bluebird": "~3.4.1",
"buffer-indexof-polyfill": "~1.0.0",
"fstream": "~1.0.10",
"listenercount": "~1.0.1",
"readable-stream": "~2.1.5",
"setimmediate": "~1.0.4"
},

@@ -31,0 +35,0 @@ "devDependencies": {

'use strict';
// Polyfills for node 0.8
require('listenercount');
require('buffer-indexof-polyfill');
require('setimmediate');
exports.Parse = require('./lib/parse');
exports.Extract = require('./lib/extract');

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc