@zip.js/zip.js 2.8.55 → 2.8.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/deno.json +1 -1
- package/dist/zip-core-external.js +43 -29
- package/dist/zip-core-external.min.js +1 -1
- package/dist/zip-core.js +43 -29
- package/dist/zip-core.min.js +1 -1
- package/dist/zip-fs-core-external.js +54 -36
- package/dist/zip-fs-core-external.min.js +1 -1
- package/dist/zip-fs-core.js +54 -36
- package/dist/zip-fs-core.min.js +1 -1
- package/dist/zip-fs-external.js +54 -36
- package/dist/zip-fs-external.min.js +1 -1
- package/dist/zip-fs-native.js +54 -36
- package/dist/zip-fs-native.min.js +1 -1
- package/dist/zip-fs.js +54 -36
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-legacy.js +43 -29
- package/dist/zip-legacy.min.js +1 -1
- package/dist/zip-native.js +43 -29
- package/dist/zip-native.min.js +1 -1
- package/dist/zip.js +43 -29
- package/dist/zip.min.js +1 -1
- package/index-native.cjs +54 -36
- package/index-native.min.js +1 -1
- package/index.cjs +54 -36
- package/index.d.cts +5 -0
- package/index.d.ts +5 -0
- package/index.min.js +1 -1
- package/lib/core/options.js +14 -0
- package/lib/core/zip-reader.js +8 -1
- package/lib/core/zip-writer.js +36 -35
- package/package.json +1 -1
package/dist/zip.js
CHANGED
|
@@ -235,6 +235,18 @@
|
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
+
function checkInteger(value, maxValue, errorMessage) {
|
|
239
|
+
if (!Number.isInteger(value) || value < 0 || value > maxValue) {
|
|
240
|
+
throw new Error(errorMessage);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function checkIntegerOption(value, maxValue, errorMessage) {
|
|
245
|
+
if (value !== UNDEFINED_VALUE) {
|
|
246
|
+
checkInteger(value, maxValue, errorMessage);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
238
250
|
function toNumber(value) {
|
|
239
251
|
return typeof value == STRING_TYPE && value.trim() ? Number(value) : value;
|
|
240
252
|
}
|
|
@@ -5051,8 +5063,15 @@
|
|
|
5051
5063
|
yield entry;
|
|
5052
5064
|
}
|
|
5053
5065
|
let offsetAfterSignature = offset;
|
|
5054
|
-
|
|
5066
|
+
let digitalSignature = readDigitalSignature(directoryArray.subarray(offset)) ||
|
|
5055
5067
|
(decryptedDirectory ? readDigitalSignature(dataAfterEncryptedDirectory) : UNDEFINED_VALUE);
|
|
5068
|
+
if (!digitalSignature && !decryptedDirectory) {
|
|
5069
|
+
const signatureRecordOffset = directoryDataOffset + offset;
|
|
5070
|
+
const signatureRecordLength = Math.min(centralDirectoryEndOffset - signatureRecordOffset, 6 + MAX_16_BITS);
|
|
5071
|
+
if (signatureRecordLength >= 6) {
|
|
5072
|
+
digitalSignature = readDigitalSignature(await readUint8Array(reader, signatureRecordOffset, signatureRecordLength));
|
|
5073
|
+
}
|
|
5074
|
+
}
|
|
5056
5075
|
if (digitalSignature) {
|
|
5057
5076
|
zipReader.digitalSignature = digitalSignature;
|
|
5058
5077
|
offsetAfterSignature = offset + 6 + digitalSignature.length;
|
|
@@ -6129,6 +6148,8 @@
|
|
|
6129
6148
|
|
|
6130
6149
|
const EXTRAFIELD_DATA_AES = new Uint8Array([0x07, 0x00, 0x02, 0x00, 0x41, 0x45, 0x03, 0x00, 0x00]);
|
|
6131
6150
|
const EXTRAFIELD_OFFSET_AES_VENDOR_VERSION = 4;
|
|
6151
|
+
const EXTRAFIELD_OFFSET_AES_COMPRESSION_METHOD = 9;
|
|
6152
|
+
const EXTRAFIELD_USDZ_MAX_LENGTH = 67;
|
|
6132
6153
|
const VENDOR_VERSION_AE_1 = 1;
|
|
6133
6154
|
const INFOZIP_EXTRA_FIELD_TYPE = "infozip";
|
|
6134
6155
|
const UNIX_EXTRA_FIELD_TYPE = "unix";
|
|
@@ -6175,16 +6196,14 @@
|
|
|
6175
6196
|
await zipReader$1.close();
|
|
6176
6197
|
await initStream(this.writer);
|
|
6177
6198
|
const { directoryOffset } = zipReader$1;
|
|
6178
|
-
let splitZipSignatureLength = 0;
|
|
6179
6199
|
if (this.addSplitZipSignature) {
|
|
6180
6200
|
delete this.addSplitZipSignature;
|
|
6181
6201
|
if (!await startsWithSplitZipSignature(reader)) {
|
|
6182
6202
|
await writeData(this.writer, getSplitZipSignatureArray());
|
|
6183
|
-
|
|
6184
|
-
this.offset += splitZipSignatureLength;
|
|
6203
|
+
this.offset += SPLIT_ZIP_FILE_SIGNATURE_LENGTH;
|
|
6185
6204
|
}
|
|
6186
6205
|
}
|
|
6187
|
-
const entryPositions = await copyZipData(this, reader, entries, directoryOffset
|
|
6206
|
+
const entryPositions = await copyZipData(this, reader, entries, directoryOffset);
|
|
6188
6207
|
this.filenames = new Set(entries.map(entry => entry.filename));
|
|
6189
6208
|
this.fileEntries = new Map(entries.map(entry => {
|
|
6190
6209
|
const {
|
|
@@ -6426,7 +6445,8 @@
|
|
|
6426
6445
|
signature: options[PROPERTY_NAME_SIGNATURE],
|
|
6427
6446
|
crc32: options.crc32 === UNDEFINED_VALUE ? options[PROPERTY_NAME_SIGNATURE] : options.crc32,
|
|
6428
6447
|
offset: zipWriter.offset - diskOffset,
|
|
6429
|
-
diskNumberStart: diskNumber
|
|
6448
|
+
diskNumberStart: diskNumber,
|
|
6449
|
+
[OPTION_USDZ]: zipWriter.options[OPTION_USDZ]
|
|
6430
6450
|
});
|
|
6431
6451
|
const headerInfo = getHeaderInfo(options);
|
|
6432
6452
|
const dataDescriptorInfo = getDataDescriptorInfo(options);
|
|
@@ -6458,15 +6478,9 @@
|
|
|
6458
6478
|
let setuid = getOptionValue(zipWriter, options, PROPERTY_NAME_SETUID);
|
|
6459
6479
|
let setgid = getOptionValue(zipWriter, options, PROPERTY_NAME_SETGID);
|
|
6460
6480
|
let sticky = getOptionValue(zipWriter, options, PROPERTY_NAME_STICKY);
|
|
6461
|
-
|
|
6462
|
-
|
|
6463
|
-
|
|
6464
|
-
if (gid !== UNDEFINED_VALUE && (!Number.isInteger(gid) || gid < 0 || gid > MAX_32_BITS)) {
|
|
6465
|
-
throw new Error(ERR_INVALID_GID);
|
|
6466
|
-
}
|
|
6467
|
-
if (unixMode !== UNDEFINED_VALUE && (!Number.isInteger(unixMode) || unixMode < 0 || unixMode > MAX_16_BITS)) {
|
|
6468
|
-
throw new Error(ERR_INVALID_UNIX_MODE);
|
|
6469
|
-
}
|
|
6481
|
+
checkIntegerOption(uid, MAX_32_BITS, ERR_INVALID_UID);
|
|
6482
|
+
checkIntegerOption(gid, MAX_32_BITS, ERR_INVALID_GID);
|
|
6483
|
+
checkIntegerOption(unixMode, MAX_16_BITS, ERR_INVALID_UNIX_MODE);
|
|
6470
6484
|
if (unixExtraFieldType !== UNDEFINED_VALUE && unixExtraFieldType !== INFOZIP_EXTRA_FIELD_TYPE && unixExtraFieldType !== UNIX_EXTRA_FIELD_TYPE) {
|
|
6471
6485
|
throw new Error(ERR_INVALID_UNIX_EXTRA_FIELD_TYPE);
|
|
6472
6486
|
}
|
|
@@ -6488,9 +6502,7 @@
|
|
|
6488
6502
|
msDosCompatible = true;
|
|
6489
6503
|
versionMadeBy = (versionMadeBy & MAX_8_BITS);
|
|
6490
6504
|
}
|
|
6491
|
-
|
|
6492
|
-
throw new Error(ERR_INVALID_MSDOS_ATTRIBUTES);
|
|
6493
|
-
}
|
|
6505
|
+
checkIntegerOption(msdosAttributesRaw, MAX_8_BITS, ERR_INVALID_MSDOS_ATTRIBUTES);
|
|
6494
6506
|
if (msdosAttributes && (typeof msdosAttributes !== OBJECT_TYPE || Array.isArray(msdosAttributes))) {
|
|
6495
6507
|
throw new Error(ERR_INVALID_MSDOS_DATA);
|
|
6496
6508
|
}
|
|
@@ -6630,9 +6642,7 @@
|
|
|
6630
6642
|
throw new Error(ERR_UNSUPPORTED_COMPRESSION);
|
|
6631
6643
|
}
|
|
6632
6644
|
let level = getNumberOptionValue(zipWriter, options, OPTION_LEVEL);
|
|
6633
|
-
|
|
6634
|
-
throw new Error(ERR_INVALID_LEVEL);
|
|
6635
|
-
}
|
|
6645
|
+
checkIntegerOption(level, MAX_LEVEL, ERR_INVALID_LEVEL);
|
|
6636
6646
|
if (zipWriter.options[OPTION_USDZ]) {
|
|
6637
6647
|
if (password !== UNDEFINED_VALUE || rawPassword !== UNDEFINED_VALUE) {
|
|
6638
6648
|
throw new Error(ERR_UNSUPPORTED_ENCRYPTION_USDZ);
|
|
@@ -6710,9 +6720,7 @@
|
|
|
6710
6720
|
let extraFieldSize = 0;
|
|
6711
6721
|
let offset = 0;
|
|
6712
6722
|
extraField.forEach((data, type) => {
|
|
6713
|
-
|
|
6714
|
-
throw new Error(ERR_INVALID_EXTRAFIELD_TYPE);
|
|
6715
|
-
}
|
|
6723
|
+
checkInteger(type, MAX_16_BITS, ERR_INVALID_EXTRAFIELD_TYPE);
|
|
6716
6724
|
if (!(data instanceof Uint8Array)) {
|
|
6717
6725
|
throw new Error(ERR_INVALID_EXTRAFIELD_DATA_TYPE);
|
|
6718
6726
|
}
|
|
@@ -7306,12 +7314,13 @@
|
|
|
7306
7314
|
if (passThrough && crc32 !== UNDEFINED_VALUE) {
|
|
7307
7315
|
rawExtraFieldAES[EXTRAFIELD_OFFSET_AES_VENDOR_VERSION] = VENDOR_VERSION_AE_1;
|
|
7308
7316
|
}
|
|
7309
|
-
rawExtraFieldAES
|
|
7317
|
+
setUint16(getDataView(rawExtraFieldAES), EXTRAFIELD_OFFSET_AES_COMPRESSION_METHOD, compressionMethod);
|
|
7310
7318
|
compressionMethod = COMPRESSION_METHOD_AES;
|
|
7311
7319
|
}
|
|
7312
7320
|
const localExtraFieldZip64Length = writeLocalExtraFieldZip64 ? getLength(rawLocalExtraFieldZip64) : 0;
|
|
7313
7321
|
const extraFieldLength = localExtraFieldZip64Length + getLength(rawExtraFieldAES, rawExtraFieldExtendedTimestamp, rawExtraFieldNTFS, rawExtraFieldUnix, rawExtraField, rawLocalExtraField);
|
|
7314
|
-
|
|
7322
|
+
const maximumUsdzExtraFieldLength = options[OPTION_USDZ] ? EXTRAFIELD_USDZ_MAX_LENGTH : 0;
|
|
7323
|
+
if (extraFieldLength + maximumUsdzExtraFieldLength > MAX_16_BITS) {
|
|
7315
7324
|
throw new Error(ERR_INVALID_EXTRAFIELD_DATA);
|
|
7316
7325
|
}
|
|
7317
7326
|
const dosLastModDate = new Date(Math.ceil(Math.floor(lastModDate.getTime() / 1000) / 2) * 2000);
|
|
@@ -7712,7 +7721,11 @@
|
|
|
7712
7721
|
signatureRecord.writeUint32(DIGITAL_SIGNATURE_RECORD_SIGNATURE);
|
|
7713
7722
|
signatureRecord.writeUint16(signatureDataLength);
|
|
7714
7723
|
signatureRecord.writeBytes(signatureData);
|
|
7715
|
-
|
|
7724
|
+
const { writer } = zipWriter;
|
|
7725
|
+
if (exceedsAvailableSize(writer, getLength(signatureRecord.array))) {
|
|
7726
|
+
await writer.closeDisk();
|
|
7727
|
+
}
|
|
7728
|
+
await writeData(writer, signatureRecord.array);
|
|
7716
7729
|
return 6 + signatureDataLength;
|
|
7717
7730
|
}
|
|
7718
7731
|
return 0;
|
|
@@ -7823,7 +7836,7 @@
|
|
|
7823
7836
|
return getUint32(getDataView(signatureArray), 0) == SPLIT_ZIP_FILE_SIGNATURE;
|
|
7824
7837
|
}
|
|
7825
7838
|
|
|
7826
|
-
async function copyZipData(zipWriter, reader, entries, directoryOffset
|
|
7839
|
+
async function copyZipData(zipWriter, reader, entries, directoryOffset) {
|
|
7827
7840
|
const { writer } = zipWriter;
|
|
7828
7841
|
const entryPositions = new Map();
|
|
7829
7842
|
if (writer.closeDisk) {
|
|
@@ -7844,9 +7857,10 @@
|
|
|
7844
7857
|
}
|
|
7845
7858
|
await copyData(zipWriter, reader, copiedLength, directoryOffset - copiedLength);
|
|
7846
7859
|
} else {
|
|
7860
|
+
const baseOffset = zipWriter.offset;
|
|
7847
7861
|
await copyData(zipWriter, reader, 0, directoryOffset);
|
|
7848
7862
|
entries.forEach(entry => entryPositions.set(entry, {
|
|
7849
|
-
offset:
|
|
7863
|
+
offset: baseOffset + getSourceOffset(reader, entry),
|
|
7850
7864
|
diskNumberStart: 0
|
|
7851
7865
|
}));
|
|
7852
7866
|
}
|