Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose more Central Directory details on ZipFile objects #78

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,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
Expand All @@ -138,7 +139,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, options.strictFileNames));
return callback(null, new ZipFile(reader, centralDirectoryOffset, centralDirectorySize, bufferReadStart + i, totalSize, entryCount, comment, false, options.autoClose, options.lazyEntries, decodeStrings, options.validateEntrySizes, options.strictFileNames));
}

// ZIP64 format
Expand Down Expand Up @@ -176,10 +177,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, options.strictFileNames));
return callback(null, new ZipFile(reader, centralDirectoryOffset, centralDirectorySize, bufferReadStart + i, totalSize, entryCount, comment, true, options.autoClose, options.lazyEntries, decodeStrings, options.validateEntrySizes, options.strictFileNames));
});
});
return;
Expand All @@ -189,7 +191,7 @@ function fromRandomAccessReader(reader, totalSize, options, callback) {
}

util.inherits(ZipFile, EventEmitter);
function ZipFile(reader, centralDirectoryOffset, fileSize, entryCount, comment, autoClose, lazyEntries, decodeStrings, validateEntrySizes, strictFileNames) {
function ZipFile(reader, centralDirectoryOffset, centralDirectorySize, endOfCentralDirectoryOffset, fileSize, entryCount, comment, zip64, autoClose, lazyEntries, decodeStrings, validateEntrySizes, strictFileNames) {
var self = this;
EventEmitter.call(self);
self.reader = reader;
Expand All @@ -203,8 +205,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;
Expand Down Expand Up @@ -372,6 +378,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)
Expand Down