Comparing version 0.10.3 to 0.10.4
@@ -40,2 +40,43 @@ var binary = require('binary'); | ||
// Zip64 File Format Notes: https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT | ||
function getZip64CentralDirectory(source, zip64CDL) { | ||
var d64loc = binary.parse(zip64CDL) | ||
.word32lu('signature') | ||
.word32lu('diskNumber') | ||
.word64lu('offsetToStartOfCentralDirectory') | ||
.word32lu('numberOfDisks') | ||
.vars; | ||
if (d64loc.signature != 0x07064b50) { | ||
throw new Error('invalid zip64 end of central dir locator signature (0x07064b50): 0x' + d64loc.signature.toString(16)); | ||
} | ||
var dir64 = PullStream(); | ||
source.stream(d64loc.offsetToStartOfCentralDirectory).pipe(dir64); | ||
return dir64.pull(56) | ||
} | ||
// Zip64 File Format Notes: https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT | ||
function parseZip64DirRecord (dir64record) { | ||
var vars = binary.parse(dir64record) | ||
.word32lu('signature') | ||
.word64lu('sizeOfCentralDirectory') | ||
.word16lu('version') | ||
.word16lu('versionsNeededToExtract') | ||
.word32lu('diskNumber') | ||
.word32lu('diskStart') | ||
.word64lu('numberOfRecordsOnDisk') | ||
.word64lu('numberOfRecords') | ||
.word64lu('sizeOfCentralDirectory') | ||
.word64lu('offsetToStartOfCentralDirectory') | ||
.vars; | ||
if (vars.signature != 0x06064b50) { | ||
throw new Error('invalid zip64 end of central dir locator signature (0x06064b50): 0x0' + vars.signature.toString(16)); | ||
} | ||
return vars | ||
} | ||
module.exports = function centralDirectory(source, options) { | ||
@@ -45,3 +86,5 @@ var endDir = PullStream(), | ||
tailSize = (options && options.tailSize) || 80, | ||
sourceSize, | ||
crxHeader, | ||
startOffset, | ||
vars; | ||
@@ -54,2 +97,3 @@ | ||
.then(function(size) { | ||
sourceSize = size; | ||
source.stream(Math.max(0,size-tailSize)).pipe(endDir); | ||
@@ -63,3 +107,3 @@ return endDir.pull(signature); | ||
var data = d.directory; | ||
var startOffset = d.crxHeader && d.crxHeader.size || 0; | ||
startOffset = d.crxHeader && d.crxHeader.size || 0; | ||
@@ -77,4 +121,26 @@ vars = binary.parse(data) | ||
vars.offsetToStartOfCentralDirectory += startOffset; | ||
// Is this zip file using zip64 format? Use same check as Go: | ||
// https://github.com/golang/go/blob/master/src/archive/zip/reader.go#L503 | ||
// For zip64 files, need to find zip64 central directory locator header to extract | ||
// relative offset for zip64 central directory record. | ||
if (vars.numberOfRecords == 0xffff|| vars.numberOfRecords == 0xffff || | ||
vars.offsetToStartOfCentralDirectory == 0xffffffff) { | ||
// Offset to zip64 CDL is 20 bytes before normal CDR | ||
const zip64CDLSize = 20 | ||
const zip64CDLOffset = sourceSize - (tailSize - endDir.match + zip64CDLSize) | ||
const zip64CDLStream = PullStream(); | ||
source.stream(zip64CDLOffset).pipe(zip64CDLStream); | ||
return zip64CDLStream.pull(zip64CDLSize) | ||
.then(function (d) { return getZip64CentralDirectory(source, d) }) | ||
.then(function (dir64record) { | ||
vars = parseZip64DirRecord(dir64record) | ||
}) | ||
} else { | ||
vars.offsetToStartOfCentralDirectory += startOffset; | ||
} | ||
}) | ||
.then(function() { | ||
source.stream(vars.offsetToStartOfCentralDirectory).pipe(records); | ||
@@ -81,0 +147,0 @@ |
@@ -33,3 +33,6 @@ var binary = require('binary'); | ||
if (vars.offsetToLocalFileHeader === 0xffffffff) | ||
vars.offsetToLocalFileHeader= extra.offset; | ||
return extra; | ||
}; | ||
}; |
@@ -58,2 +58,5 @@ var Stream = require('stream'); | ||
if (match !== -1) { | ||
// store signature match byte offset to allow us to reference | ||
// this for zip64 offset | ||
self.match = match | ||
if (includeEof) match = match + eof.length; | ||
@@ -60,0 +63,0 @@ packet = self.buffer.slice(0,match); |
{ | ||
"name": "unzipper", | ||
"version": "0.10.3", | ||
"version": "0.10.4", | ||
"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
50872
994