From e81a932ff9f79ae8efafacfd929e12549e25fbec Mon Sep 17 00:00:00 2001 From: Ziggy Jonsson Date: Sat, 1 Jun 2019 08:23:42 -0400 Subject: [PATCH] Use endOfDirectory file header instead of local header --- lib/Open/directory.js | 3 ++- lib/Open/unzip.js | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/Open/directory.js b/lib/Open/directory.js index 186a639..d4dbcde 100644 --- a/lib/Open/directory.js +++ b/lib/Open/directory.js @@ -71,8 +71,9 @@ module.exports = function centralDirectory(source, options) { }) .then(function(comment) { vars.comment = comment; + vars.type = (vars.uncompressedSize === 0 && /[\/\\]$/.test(vars.path)) ? 'Directory' : 'File'; vars.stream = function(_password) { - return unzip(source, vars.offsetToLocalFileHeader,_password); + return unzip(source, vars.offsetToLocalFileHeader,_password, vars); }; vars.buffer = function(_password) { return BufferStream(vars.stream(_password)); diff --git a/lib/Open/unzip.js b/lib/Open/unzip.js index 0bf7788..b157ab5 100644 --- a/lib/Open/unzip.js +++ b/lib/Open/unzip.js @@ -11,7 +11,7 @@ var Buffer = require('../Buffer'); if (!Stream.Writable || !Stream.Writable.prototype.destroy) Stream = require('readable-stream'); -module.exports = function unzip(source,offset,_password) { +module.exports = function unzip(source,offset,_password, directoryVars) { var file = PullStream(), entry = Stream.PassThrough(), vars; @@ -44,6 +44,9 @@ module.exports = function unzip(source,offset,_password) { .then(function(extraField) { var checkEncryption; vars.extra = parseExtraField(extraField, vars); + // Ignore logal file header vars if the directory vars are available + if (directoryVars && directoryVars.compressedSize) vars = directoryVars; + if (vars.flags & 0x01) checkEncryption = file.pull(12) .then(function(header) { if (!_password)