Comparing version 0.9.0-rc4 to 0.9.0-rc5
@@ -1,6 +0,5 @@ | ||
var binary = require('binary'); | ||
var PullStream = require('../PullStream'); | ||
var unzip = require('./unzip'); | ||
var Promise = require('bluebird'); | ||
var BufferStream = require('../BufferStream'); | ||
var read = require('../read'); | ||
@@ -12,5 +11,3 @@ var signature = Buffer(4); | ||
var endDir = PullStream(), | ||
records = PullStream(), | ||
self = this, | ||
vars; | ||
records = PullStream(); | ||
@@ -23,62 +20,32 @@ return source.size() | ||
.then(function() { | ||
return endDir.pull(22); | ||
return read.endOfDirectory(endDir); | ||
}) | ||
.then(function(data) { | ||
vars = binary.parse(data) | ||
.word32lu('signature') | ||
.word16lu('diskNumber') | ||
.word16lu('diskStart') | ||
.word16lu('numberOfRecordsOnDisk') | ||
.word16lu('numberOfRecords') | ||
.word32lu('sizeOfCentralDirectory') | ||
.word32lu('offsetToStartOfCentralDirectory') | ||
.word16lu('commentLength') | ||
.vars; | ||
.then(function(vars) { | ||
source.stream(vars.offsetToStartOfCentralDirectory).pipe(records); | ||
vars.files = Promise.mapSeries(Array(vars.numberOfRecords),function() { | ||
return records.pull(46).then(function(data) { | ||
var vars = binary.parse(data) | ||
.word32lu('signature') | ||
.word16lu('versionMadeBy') | ||
.word16lu('versionsNeededToExtract') | ||
.word16lu('flags') | ||
.word16lu('compressionMethod') | ||
.word16lu('lastModifiedTime') | ||
.word16lu('lastModifiedDate') | ||
.word32lu('crc32') | ||
.word32lu('compressedSize') | ||
.word32lu('uncompressedSize') | ||
.word16lu('fileNameLength') | ||
.word16lu('extraFieldLength') | ||
.word16lu('fileCommentLength') | ||
.word16lu('diskNumber') | ||
.word16lu('internalFileAttributes') | ||
.word32lu('externalFileAttributes') | ||
.word32lu('offsetToLocalFileHeader') | ||
.vars; | ||
return read.directoryFileHeader(records) | ||
.then(function(file) { | ||
file.raw = function(_password) { | ||
var p = source.stream(file.offsetToLocalFileHeader).pipe(PullStream()); | ||
return read.fileStream(p,{password: _password,raw: true}); | ||
}; | ||
return records.pull(vars.fileNameLength).then(function(fileName) { | ||
vars.path = fileName.toString('utf8'); | ||
return records.pull(vars.extraFieldLength); | ||
}) | ||
.then(function(extraField) { | ||
return records.pull(vars.fileCommentLength); | ||
}) | ||
.then(function(comment) { | ||
vars.comment = comment; | ||
vars.stream = function(_password) { | ||
return unzip(source, vars.offsetToLocalFileHeader,_password); | ||
}; | ||
vars.buffer = function(_password) { | ||
return BufferStream(vars.stream(_password)); | ||
}; | ||
return vars; | ||
}); | ||
file.stream = function(_password) { | ||
var p = source.stream(file.offsetToLocalFileHeader).pipe(PullStream()); | ||
return read.fileStream(p,{password:_password}); | ||
}; | ||
file.buffer = function(_password) { | ||
return BufferStream(file.stream(_password)); | ||
}; | ||
return file; | ||
}); | ||
}); | ||
return Promise.props(vars); | ||
}); | ||
return Promise.props(vars); | ||
}); | ||
}; |
212
lib/parse.js
var util = require('util'); | ||
var zlib = require('zlib'); | ||
var Stream = require('stream'); | ||
var binary = require('binary'); | ||
var Promise = require('bluebird'); | ||
var PullStream = require('./PullStream'); | ||
var NoopStream = require('./NoopStream'); | ||
var BufferStream = require('./BufferStream'); | ||
var read = require('./read'); | ||
@@ -39,17 +36,22 @@ // Backwards compatibility for node 0.8 | ||
// Read signature and put back on buffer | ||
var signature = data.readUInt32LE(0); | ||
self.buffer = Buffer.concat([data,self.buffer]); | ||
if (signature === 0x04034b50) { | ||
if (signature === 0x04034b50) | ||
return self._readFile(); | ||
} | ||
else if (signature === 0x02014b50) { | ||
self.__ended = true; | ||
return self._readCentralDirectoryFileHeader(); | ||
return read.directoryFileHeader(self) | ||
.then(function(vars) { | ||
return self._readRecord(); | ||
}); | ||
} | ||
else if (signature === 0x06054b50) { | ||
return self._readEndOfCentralDirectoryRecord(); | ||
} | ||
else if (self.__ended) { | ||
else if (signature === 0x06054b50 || self.__ended) { | ||
return self.pull(endDirectorySignature).then(function() { | ||
return self._readEndOfCentralDirectoryRecord(); | ||
return read.endOfDirectory(self); | ||
}) | ||
.then(function() { | ||
self.end(); | ||
self.push(null); | ||
}); | ||
@@ -64,176 +66,40 @@ } | ||
var self = this; | ||
self.pull(26).then(function(data) { | ||
var vars = binary.parse(data) | ||
.word16lu('versionsNeededToExtract') | ||
.word16lu('flags') | ||
.word16lu('compressionMethod') | ||
.word16lu('lastModifiedTime') | ||
.word16lu('lastModifiedDate') | ||
.word32lu('crc32') | ||
.word32lu('compressedSize') | ||
.word32lu('uncompressedSize') | ||
.word16lu('fileNameLength') | ||
.word16lu('extraFieldLength') | ||
.vars; | ||
var entry = read.fileStream(self,self._opts); | ||
return self.pull(vars.fileNameLength).then(function(fileName) { | ||
fileName = fileName.toString('utf8'); | ||
var entry = Stream.PassThrough(); | ||
entry.autodrain = function() { | ||
return new Promise(function(resolve,reject) { | ||
entry.pipe(NoopStream()); | ||
entry.on('finish',resolve); | ||
entry.on('error',reject); | ||
}); | ||
}; | ||
entry.vars.then(function(vars) { | ||
entry.vars = vars; | ||
var fileSizeKnown = !(vars.flags & 0x08); | ||
entry.path = vars.path; | ||
entry.props = {}; | ||
entry.props.path = vars.fileName; | ||
entry.type = (vars.compressedSize === 0 && /[\/\\]$/.test(vars.path)) ? 'Directory' : 'File'; | ||
entry.buffer = function() { | ||
return BufferStream(entry); | ||
}; | ||
entry.autodrain = function() { | ||
entry.autodraining = true; | ||
return new Promise(function(resolve,reject) { | ||
entry.on('finish',resolve); | ||
entry.on('error',reject); | ||
}); | ||
}; | ||
entry.path = fileName; | ||
entry.props = {}; | ||
entry.props.path = fileName; | ||
entry.type = (vars.compressedSize === 0 && /[\/\\]$/.test(fileName)) ? 'Directory' : 'File'; | ||
self.emit('entry',entry); | ||
if (self._opts.verbose) { | ||
if (entry.type === 'Directory') { | ||
console.log(' creating:', fileName); | ||
} else if (entry.type === 'File') { | ||
if (vars.compressionMethod === 0) { | ||
console.log(' extracting:', fileName); | ||
} else { | ||
console.log(' inflating:', fileName); | ||
} | ||
} | ||
} | ||
if (self._readableState.pipesCount) | ||
self.push(entry); | ||
self.emit('entry', entry); | ||
if (self._readableState.pipesCount) | ||
self.push(entry); | ||
entry | ||
.on('error',function(err) { self.emit('error',err);}) | ||
.on('finish', function() { | ||
Promise.resolve(!fileSizeKnown && read.dataDescriptor(self)) | ||
.then(function() { | ||
return self._readRecord(); | ||
}); | ||
self.pull(vars.extraFieldLength).then(function(extraField) { | ||
var extra = binary.parse(extraField) | ||
.word16lu('signature') | ||
.word16lu('partsize') | ||
.word64lu('uncompressedSize') | ||
.word64lu('compressedSize') | ||
.word64lu('offset') | ||
.word64lu('disknum') | ||
.vars; | ||
if (vars.compressedSize === 0xffffffff) | ||
vars.compressedSize = extra.compressedSize; | ||
if (vars.uncompressedSize === 0xffffffff) | ||
vars.uncompressedSize= extra.uncompressedSize; | ||
if (self._opts.verbose) | ||
console.log({ | ||
filename:fileName, | ||
vars: vars, | ||
extra: extra | ||
}); | ||
var fileSizeKnown = !(vars.flags & 0x08), | ||
eof; | ||
var inflater = vars.compressionMethod ? zlib.createInflateRaw() : Stream.PassThrough(); | ||
if (fileSizeKnown) { | ||
entry.size = vars.uncompressedSize; | ||
eof = vars.compressedSize; | ||
} else { | ||
eof = new Buffer(4); | ||
eof.writeUInt32LE(0x08074b50, 0); | ||
} | ||
self.stream(eof) | ||
.pipe(inflater) | ||
.on('error',function(err) { self.emit('error',err);}) | ||
.pipe(entry) | ||
.on('finish', function() { | ||
return fileSizeKnown ? self._readRecord() : self._processDataDescriptor(entry); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}; | ||
Parse.prototype._processDataDescriptor = function (entry) { | ||
var self = this; | ||
self.pull(16).then(function(data) { | ||
var vars = binary.parse(data) | ||
.word32lu('dataDescriptorSignature') | ||
.word32lu('crc32') | ||
.word32lu('compressedSize') | ||
.word32lu('uncompressedSize') | ||
.vars; | ||
entry.size = vars.uncompressedSize; | ||
self._readRecord(); | ||
}); | ||
}; | ||
Parse.prototype._readCentralDirectoryFileHeader = function () { | ||
var self = this; | ||
self.pull(42).then(function(data) { | ||
var vars = binary.parse(data) | ||
.word16lu('versionMadeBy') | ||
.word16lu('versionsNeededToExtract') | ||
.word16lu('flags') | ||
.word16lu('compressionMethod') | ||
.word16lu('lastModifiedTime') | ||
.word16lu('lastModifiedDate') | ||
.word32lu('crc32') | ||
.word32lu('compressedSize') | ||
.word32lu('uncompressedSize') | ||
.word16lu('fileNameLength') | ||
.word16lu('extraFieldLength') | ||
.word16lu('fileCommentLength') | ||
.word16lu('diskNumber') | ||
.word16lu('internalFileAttributes') | ||
.word32lu('externalFileAttributes') | ||
.word32lu('offsetToLocalFileHeader') | ||
.vars; | ||
return self.pull(vars.fileNameLength).then(function(fileName) { | ||
vars.fileName = fileName.toString('utf8'); | ||
return self.pull(vars.extraFieldLength); | ||
}) | ||
.then(function(extraField) { | ||
return self.pull(vars.fileCommentLength); | ||
}) | ||
.then(function(fileComment) { | ||
return self._readRecord(); | ||
}); | ||
}); | ||
}; | ||
Parse.prototype._readEndOfCentralDirectoryRecord = function() { | ||
var self = this; | ||
self.pull(18).then(function(data) { | ||
var vars = binary.parse(data) | ||
.word16lu('diskNumber') | ||
.word16lu('diskStart') | ||
.word16lu('numberOfRecordsOnDisk') | ||
.word16lu('numberOfRecords') | ||
.word32lu('sizeOfCentralDirectory') | ||
.word32lu('offsetToStartOfCentralDirectory') | ||
.word16lu('commentLength') | ||
.vars; | ||
self.pull(vars.commentLength).then(function(comment) { | ||
comment = comment.toString('utf8'); | ||
self.end(); | ||
self.push(null); | ||
}); | ||
}); | ||
}; | ||
Parse.prototype.promise = function() { | ||
@@ -240,0 +106,0 @@ var self = this; |
var Stream = require('stream'); | ||
var Parse = require('./parse'); | ||
var duplexer2 = require('duplexer2'); | ||
var BufferStream = require('./BufferStream'); | ||
@@ -10,2 +11,3 @@ // Backwards compatibility for node 0.8 | ||
function parseOne(match,opts) { | ||
opts = opts || {}; | ||
var inStream = Stream.PassThrough({objectMode:true}); | ||
@@ -18,2 +20,3 @@ var outStream = Stream.PassThrough(); | ||
transform._transform = function(entry,e,cb) { | ||
entry.password = opts.password; | ||
if (found || (re && !re.exec(entry.path))) { | ||
@@ -43,3 +46,8 @@ entry.autodrain(); | ||
return duplexer2(inStream,outStream); | ||
var out = duplexer2(inStream,outStream); | ||
out.buffer = function() { | ||
return BufferStream(outStream); | ||
}; | ||
return out; | ||
} | ||
@@ -46,0 +54,0 @@ |
@@ -36,3 +36,3 @@ var Stream = require('stream'); | ||
var p = Stream.PassThrough(); | ||
var count = 0,done,packet,self= this; | ||
var done,packet,self= this; | ||
@@ -65,9 +65,8 @@ function pull() { | ||
if (!done) { | ||
if (self.finished && !this.__ended) { | ||
if (self.finished && !self.__ended) { | ||
self.removeListener('chunk',pull); | ||
p.emit('error','FILE_ENDED'); | ||
self.emit('error','FILE_ENDED'); | ||
this.__ended = true; | ||
return; | ||
} | ||
} else { | ||
@@ -74,0 +73,0 @@ self.removeListener('chunk',pull); |
{ | ||
"name": "unzipper", | ||
"version": "0.9.0-rc4", | ||
"version": "0.9.0-rc5", | ||
"description": "Unzip cross-platform streaming API ", | ||
@@ -24,5 +24,2 @@ "author": "Evan Oxfeld <eoxfeld@gmail.com>", | ||
}, | ||
"bin": { | ||
"unzipper": "./bin/unzipper.js" | ||
}, | ||
"license": "MIT", | ||
@@ -47,10 +44,2 @@ "dependencies": { | ||
}, | ||
"peerDependencies": { | ||
"fstream": "~1.0.10", | ||
"inquirer": "~2.0.0", | ||
"minimist": "~1.2.0", | ||
"multi-progress": "~2.0.0", | ||
"progress": "~1.1.8", | ||
"request": "~2.79.0" | ||
}, | ||
"directories": { | ||
@@ -57,0 +46,0 @@ "example": "examples", |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
9
2
29725
21
616
1