From cbd4161a7e6fd0c80ab8a3eaf8f0a218e653ef46 Mon Sep 17 00:00:00 2001 From: dtcookie <41952460+dtcookie@users.noreply.github.com> Date: Sun, 12 Nov 2023 18:37:46 +0100 Subject: [PATCH] Added functionality to read UTF-8 entry name from 0x7075 extra info --- node_stream_zip.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/node_stream_zip.js b/node_stream_zip.js index d95bbef..1643926 100644 --- a/node_stream_zip.js +++ b/node_stream_zip.js @@ -130,6 +130,7 @@ const consts = { ID_IBM1: 0x0065, ID_IBM2: 0x0066, ID_POSZIP: 0x4690, + ID_UNICODE_PATH: 0x7075, EF_ZIP64_OR_32: 0xffffffff, EF_ZIP64_OR_16: 0xffff, @@ -910,10 +911,24 @@ class ZipEntry { if (consts.ID_ZIP64 === signature) { this.parseZip64Extra(data, offset, size); } + if (consts.ID_UNICODE_PATH === signature) { + this.parseUnicodeFileName(data, offset, size); + } offset += size; } } + parseUnicodeFileName(data, offset, length) { + readUInt8(data, offset) // version + offset += 1 + length -= 1 + var nameCRC32 = readUInt32LE(data, offset) + offset += 4 + length -= 4 + const nameData = data.slice(offset, (offset += length)); + this.name = nameData.toString('utf-8') + } + parseZip64Extra(data, offset, length) { if (length >= 8 && this.size === consts.EF_ZIP64_OR_32) { this.size = readUInt64LE(data, offset); @@ -1207,4 +1222,12 @@ function readUInt64LE(buffer, offset) { return buffer.readUInt32LE(offset + 4) * 0x0000000100000000 + buffer.readUInt32LE(offset); } +function readUInt32LE(buffer, offset) { + return buffer.readUInt32LE(offset); +} + +function readUInt8(buffer, offset) { + return buffer.readUInt8(offset) +} + module.exports = StreamZip;