Comparing version 0.7.5 to 0.7.6
@@ -7,2 +7,4 @@ var util = require('util'); | ||
var PullStream = require('./PullStream'); | ||
var NoopStream = require('./NoopStream'); | ||
var BufferStream = require('./BufferStream'); | ||
@@ -13,12 +15,5 @@ // Backwards compatibility for node 0.8 | ||
function NoopStream() { | ||
if (!(this instanceof NoopStream)) { | ||
return new NoopStream(); | ||
} | ||
Stream.Transform.call(this); | ||
} | ||
util.inherits(NoopStream,Stream.Transform); | ||
var endDirectorySignature = new Buffer(4); | ||
endDirectorySignature.writeUInt32LE(0x06054b50, 0); | ||
NoopStream.prototype._transform = function(d,e,cb) { cb() ;}; | ||
function Parse(opts) { | ||
@@ -42,3 +37,3 @@ if (!(this instanceof Parse)) { | ||
var self = this; | ||
self.pull(4).then(function(data) { | ||
return self.pull(4).then(function(data) { | ||
if (data.length === 0) | ||
@@ -48,20 +43,19 @@ return; | ||
var signature = data.readUInt32LE(0); | ||
if (signature === 0x04034b50) | ||
self._readFile(); | ||
if (signature === 0x04034b50) { | ||
return self._readFile(); | ||
} | ||
else if (signature === 0x02014b50) { | ||
// Hack to (optionally) bypass central directory at the end | ||
// A proper fix would be to debug invalid signature 0x6064b50 | ||
if (self._opts.bypassDirectory) { | ||
self.__ended = true; | ||
self.stream(Infinity).pipe(NoopStream()).on('finish',function() { | ||
self.end(); | ||
self.push(null); | ||
self.__ended = true; | ||
return self._readCentralDirectoryFileHeader(); | ||
} | ||
else if (signature === 0x06054b50) { | ||
return self._readEndOfCentralDirectoryRecord(); | ||
} | ||
else if (self.__ended) { | ||
return self.pull(endDirectorySignature).then(function() { | ||
return self._readEndOfCentralDirectoryRecord(); | ||
}); | ||
} | ||
else | ||
self._readCentralDirectoryFileHeader(); | ||
} | ||
else if (signature === 0x06054b50) | ||
self._readEndOfCentralDirectoryRecord(); | ||
else | ||
else | ||
self.emit('error', Error('invalid signature: 0x' + signature.toString(16))); | ||
@@ -100,16 +94,3 @@ }); | ||
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); | ||
}); | ||
return BufferStream(entry); | ||
}; | ||
@@ -226,10 +207,10 @@ | ||
return self.pull(vars.fileNameLength).then(function(fileName) { | ||
fileName = fileName.toString('utf8'); | ||
self.pull(vars.extraFieldLength).then(function(extraField) { | ||
self.pull(vars.fileCommentLength).then(function(fileComment) { | ||
return self._readRecord(); | ||
}); | ||
}); | ||
vars.fileName = fileName.toString('utf8'); | ||
return self.pull(vars.extraFieldLength); | ||
}) | ||
.then(function(extraField) { | ||
return self.pull(vars.fileCommentLength); | ||
}) | ||
.then(function(fileComment) { | ||
return self._readRecord(); | ||
}); | ||
@@ -239,3 +220,3 @@ }); | ||
Parse.prototype._readEndOfCentralDirectoryRecord = function () { | ||
Parse.prototype._readEndOfCentralDirectoryRecord = function() { | ||
var self = this; | ||
@@ -254,12 +235,8 @@ self.pull(18).then(function(data) { | ||
if (vars.commentLength) { | ||
self.pull(vars.commentLength).then(function(comment) { | ||
comment = comment.toString('utf8'); | ||
self.end(); | ||
self.push(null); | ||
}); | ||
} else { | ||
self.pull(vars.commentLength).then(function(comment) { | ||
comment = comment.toString('utf8'); | ||
self.end(); | ||
self.push(null); | ||
} | ||
}); | ||
}); | ||
@@ -266,0 +243,0 @@ }; |
@@ -99,2 +99,13 @@ var Stream = require('stream'); | ||
PullStream.prototype.pull = function(eof,includeEof) { | ||
if (eof === 0) return Promise.resolve(''); | ||
// If we already have the required data in buffer | ||
// we can resolve the request immediately | ||
if (!isNaN(eof) && this.buffer.length > eof) { | ||
var data = this.buffer.slice(0,eof); | ||
this.buffer = this.buffer.slice(eof); | ||
return Promise.resolve(data); | ||
} | ||
// Otherwise we stream until we have it | ||
var buffer = new Buffer(''), | ||
@@ -101,0 +112,0 @@ self = this; |
{ | ||
"name": "unzipper", | ||
"version": "0.7.5", | ||
"version": "0.7.6", | ||
"description": "Unzip cross-platform streaming API ", | ||
@@ -5,0 +5,0 @@ "author": "Evan Oxfeld <eoxfeld@gmail.com>", |
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
44935
32
724