Skip to content

Commit

Permalink
Export central directory attributes in ZipFile object
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Apr 22, 2018
1 parent 57099c7 commit da2cfaf
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit da2cfaf

Please sign in to comment.