diff --git a/index.js b/index.js index ae1fea6..f397b33 100644 --- a/index.js +++ b/index.js @@ -120,6 +120,7 @@ function fromRandomAccessReader(reader, totalSize, options, callback) { // 10 - Total number of central directory records var entryCount = eocdrBuffer.readUInt16LE(10); // 12 - Size of central directory (bytes) + var centralDirectorySize = eocdrBuffer.readUInt32LE(12); // 16 - Offset of start of central directory, relative to start of archive var centralDirectoryOffset = eocdrBuffer.readUInt32LE(16); // 20 - Comment length @@ -134,7 +135,7 @@ function fromRandomAccessReader(reader, totalSize, options, callback) { : eocdrBuffer.slice(22); if (!(entryCount === 0xffff || centralDirectoryOffset === 0xffffffff)) { - return callback(null, new ZipFile(reader, centralDirectoryOffset, totalSize, entryCount, comment, options.autoClose, options.lazyEntries, decodeStrings, options.validateEntrySizes)); + return callback(null, new ZipFile(reader, centralDirectoryOffset, centralDirectorySize, bufferReadStart + i, totalSize, entryCount, comment, false, options.autoClose, options.lazyEntries, decodeStrings, options.validateEntrySizes)); } // ZIP64 format @@ -172,10 +173,11 @@ function fromRandomAccessReader(reader, totalSize, options, callback) { // 32 - total number of entries in the central directory 8 bytes entryCount = readUInt64LE(zip64EocdrBuffer, 32); // 40 - size of the central directory 8 bytes + centralDirectorySize = readUInt64LE(zip64EocdrBuffer, 40); // 48 - offset of start of central directory with respect to the starting disk number 8 bytes centralDirectoryOffset = readUInt64LE(zip64EocdrBuffer, 48); // 56 - zip64 extensible data sector (variable size) - return callback(null, new ZipFile(reader, centralDirectoryOffset, totalSize, entryCount, comment, options.autoClose, options.lazyEntries, decodeStrings, options.validateEntrySizes)); + return callback(null, new ZipFile(reader, centralDirectoryOffset, centralDirectorySize, bufferReadStart + i, totalSize, entryCount, comment, true, options.autoClose, options.lazyEntries, decodeStrings, options.validateEntrySizes)); }); }); return; @@ -185,7 +187,7 @@ function fromRandomAccessReader(reader, totalSize, options, callback) { } util.inherits(ZipFile, EventEmitter); -function ZipFile(reader, centralDirectoryOffset, fileSize, entryCount, comment, autoClose, lazyEntries, decodeStrings, validateEntrySizes) { +function ZipFile(reader, centralDirectoryOffset, centralDirectorySize, endOfCentralDirectoryOffset, fileSize, entryCount, comment, zip64, autoClose, lazyEntries, decodeStrings, validateEntrySizes) { var self = this; EventEmitter.call(self); self.reader = reader; @@ -199,8 +201,12 @@ function ZipFile(reader, centralDirectoryOffset, fileSize, entryCount, comment, }); self.readEntryCursor = centralDirectoryOffset; self.fileSize = fileSize; + self.centralDirectoryOffset = centralDirectoryOffset; + self.centralDirectorySize = centralDirectorySize; + self.endOfCentralDirectoryOffset = endOfCentralDirectoryOffset; self.entryCount = entryCount; self.comment = comment; + self.zip64 = zip64; self.entriesRead = 0; self.autoClose = !!autoClose; self.lazyEntries = !!lazyEntries; @@ -367,6 +373,9 @@ ZipFile.prototype._readEntry = function() { index += 8; } // 24 - Disk Start Number 4 bytes + entry.zip64 = true; + } else { + entry.zip64 = false; } // check for Info-ZIP Unicode Path Extra Field (0x7075)