@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/deno.json
CHANGED
|
@@ -226,6 +226,18 @@ function checkPasswordOption(password, rawPassword) {
|
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
+
function checkInteger(value, maxValue, errorMessage) {
|
|
230
|
+
if (!Number.isInteger(value) || value < 0 || value > maxValue) {
|
|
231
|
+
throw new Error(errorMessage);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function checkIntegerOption(value, maxValue, errorMessage) {
|
|
236
|
+
if (value !== UNDEFINED_VALUE) {
|
|
237
|
+
checkInteger(value, maxValue, errorMessage);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
229
241
|
function toNumber(value) {
|
|
230
242
|
return typeof value == STRING_TYPE && value.trim() ? Number(value) : value;
|
|
231
243
|
}
|
|
@@ -5076,8 +5088,15 @@ class ZipReader {
|
|
|
5076
5088
|
yield entry;
|
|
5077
5089
|
}
|
|
5078
5090
|
let offsetAfterSignature = offset;
|
|
5079
|
-
|
|
5091
|
+
let digitalSignature = readDigitalSignature(directoryArray.subarray(offset)) ||
|
|
5080
5092
|
(decryptedDirectory ? readDigitalSignature(dataAfterEncryptedDirectory) : UNDEFINED_VALUE);
|
|
5093
|
+
if (!digitalSignature && !decryptedDirectory) {
|
|
5094
|
+
const signatureRecordOffset = directoryDataOffset + offset;
|
|
5095
|
+
const signatureRecordLength = Math.min(centralDirectoryEndOffset - signatureRecordOffset, 6 + MAX_16_BITS);
|
|
5096
|
+
if (signatureRecordLength >= 6) {
|
|
5097
|
+
digitalSignature = readDigitalSignature(await readUint8Array(reader, signatureRecordOffset, signatureRecordLength));
|
|
5098
|
+
}
|
|
5099
|
+
}
|
|
5081
5100
|
if (digitalSignature) {
|
|
5082
5101
|
zipReader.digitalSignature = digitalSignature;
|
|
5083
5102
|
offsetAfterSignature = offset + 6 + digitalSignature.length;
|
|
@@ -6154,6 +6173,8 @@ const ERR_INVALID_SIGNATURE_DATA = "Signature data exceeds 64KB";
|
|
|
6154
6173
|
|
|
6155
6174
|
const EXTRAFIELD_DATA_AES = new Uint8Array([0x07, 0x00, 0x02, 0x00, 0x41, 0x45, 0x03, 0x00, 0x00]);
|
|
6156
6175
|
const EXTRAFIELD_OFFSET_AES_VENDOR_VERSION = 4;
|
|
6176
|
+
const EXTRAFIELD_OFFSET_AES_COMPRESSION_METHOD = 9;
|
|
6177
|
+
const EXTRAFIELD_USDZ_MAX_LENGTH = 67;
|
|
6157
6178
|
const VENDOR_VERSION_AE_1 = 1;
|
|
6158
6179
|
const INFOZIP_EXTRA_FIELD_TYPE = "infozip";
|
|
6159
6180
|
const UNIX_EXTRA_FIELD_TYPE = "unix";
|
|
@@ -6200,16 +6221,14 @@ class ZipWriter {
|
|
|
6200
6221
|
await zipReader$1.close();
|
|
6201
6222
|
await initStream(this.writer);
|
|
6202
6223
|
const { directoryOffset } = zipReader$1;
|
|
6203
|
-
let splitZipSignatureLength = 0;
|
|
6204
6224
|
if (this.addSplitZipSignature) {
|
|
6205
6225
|
delete this.addSplitZipSignature;
|
|
6206
6226
|
if (!await startsWithSplitZipSignature(reader)) {
|
|
6207
6227
|
await writeData(this.writer, getSplitZipSignatureArray());
|
|
6208
|
-
|
|
6209
|
-
this.offset += splitZipSignatureLength;
|
|
6228
|
+
this.offset += SPLIT_ZIP_FILE_SIGNATURE_LENGTH;
|
|
6210
6229
|
}
|
|
6211
6230
|
}
|
|
6212
|
-
const entryPositions = await copyZipData(this, reader, entries, directoryOffset
|
|
6231
|
+
const entryPositions = await copyZipData(this, reader, entries, directoryOffset);
|
|
6213
6232
|
this.filenames = new Set(entries.map(entry => entry.filename));
|
|
6214
6233
|
this.fileEntries = new Map(entries.map(entry => {
|
|
6215
6234
|
const {
|
|
@@ -6451,7 +6470,8 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
6451
6470
|
signature: options[PROPERTY_NAME_SIGNATURE],
|
|
6452
6471
|
crc32: options.crc32 === UNDEFINED_VALUE ? options[PROPERTY_NAME_SIGNATURE] : options.crc32,
|
|
6453
6472
|
offset: zipWriter.offset - diskOffset,
|
|
6454
|
-
diskNumberStart: diskNumber
|
|
6473
|
+
diskNumberStart: diskNumber,
|
|
6474
|
+
[OPTION_USDZ]: zipWriter.options[OPTION_USDZ]
|
|
6455
6475
|
});
|
|
6456
6476
|
const headerInfo = getHeaderInfo(options);
|
|
6457
6477
|
const dataDescriptorInfo = getDataDescriptorInfo(options);
|
|
@@ -6483,15 +6503,9 @@ function resolveAttributes(zipWriter, name, options) {
|
|
|
6483
6503
|
let setuid = getOptionValue(zipWriter, options, PROPERTY_NAME_SETUID);
|
|
6484
6504
|
let setgid = getOptionValue(zipWriter, options, PROPERTY_NAME_SETGID);
|
|
6485
6505
|
let sticky = getOptionValue(zipWriter, options, PROPERTY_NAME_STICKY);
|
|
6486
|
-
|
|
6487
|
-
|
|
6488
|
-
|
|
6489
|
-
if (gid !== UNDEFINED_VALUE && (!Number.isInteger(gid) || gid < 0 || gid > MAX_32_BITS)) {
|
|
6490
|
-
throw new Error(ERR_INVALID_GID);
|
|
6491
|
-
}
|
|
6492
|
-
if (unixMode !== UNDEFINED_VALUE && (!Number.isInteger(unixMode) || unixMode < 0 || unixMode > MAX_16_BITS)) {
|
|
6493
|
-
throw new Error(ERR_INVALID_UNIX_MODE);
|
|
6494
|
-
}
|
|
6506
|
+
checkIntegerOption(uid, MAX_32_BITS, ERR_INVALID_UID);
|
|
6507
|
+
checkIntegerOption(gid, MAX_32_BITS, ERR_INVALID_GID);
|
|
6508
|
+
checkIntegerOption(unixMode, MAX_16_BITS, ERR_INVALID_UNIX_MODE);
|
|
6495
6509
|
if (unixExtraFieldType !== UNDEFINED_VALUE && unixExtraFieldType !== INFOZIP_EXTRA_FIELD_TYPE && unixExtraFieldType !== UNIX_EXTRA_FIELD_TYPE) {
|
|
6496
6510
|
throw new Error(ERR_INVALID_UNIX_EXTRA_FIELD_TYPE);
|
|
6497
6511
|
}
|
|
@@ -6513,9 +6527,7 @@ function resolveAttributes(zipWriter, name, options) {
|
|
|
6513
6527
|
msDosCompatible = true;
|
|
6514
6528
|
versionMadeBy = (versionMadeBy & MAX_8_BITS);
|
|
6515
6529
|
}
|
|
6516
|
-
|
|
6517
|
-
throw new Error(ERR_INVALID_MSDOS_ATTRIBUTES);
|
|
6518
|
-
}
|
|
6530
|
+
checkIntegerOption(msdosAttributesRaw, MAX_8_BITS, ERR_INVALID_MSDOS_ATTRIBUTES);
|
|
6519
6531
|
if (msdosAttributes && (typeof msdosAttributes !== OBJECT_TYPE || Array.isArray(msdosAttributes))) {
|
|
6520
6532
|
throw new Error(ERR_INVALID_MSDOS_DATA);
|
|
6521
6533
|
}
|
|
@@ -6655,9 +6667,7 @@ function resolveMetadata(zipWriter, name, options) {
|
|
|
6655
6667
|
throw new Error(ERR_UNSUPPORTED_COMPRESSION);
|
|
6656
6668
|
}
|
|
6657
6669
|
let level = getNumberOptionValue(zipWriter, options, OPTION_LEVEL);
|
|
6658
|
-
|
|
6659
|
-
throw new Error(ERR_INVALID_LEVEL);
|
|
6660
|
-
}
|
|
6670
|
+
checkIntegerOption(level, MAX_LEVEL, ERR_INVALID_LEVEL);
|
|
6661
6671
|
if (zipWriter.options[OPTION_USDZ]) {
|
|
6662
6672
|
if (password !== UNDEFINED_VALUE || rawPassword !== UNDEFINED_VALUE) {
|
|
6663
6673
|
throw new Error(ERR_UNSUPPORTED_ENCRYPTION_USDZ);
|
|
@@ -6735,9 +6745,7 @@ function serializeExtraField(extraField) {
|
|
|
6735
6745
|
let extraFieldSize = 0;
|
|
6736
6746
|
let offset = 0;
|
|
6737
6747
|
extraField.forEach((data, type) => {
|
|
6738
|
-
|
|
6739
|
-
throw new Error(ERR_INVALID_EXTRAFIELD_TYPE);
|
|
6740
|
-
}
|
|
6748
|
+
checkInteger(type, MAX_16_BITS, ERR_INVALID_EXTRAFIELD_TYPE);
|
|
6741
6749
|
if (!(data instanceof Uint8Array)) {
|
|
6742
6750
|
throw new Error(ERR_INVALID_EXTRAFIELD_DATA_TYPE);
|
|
6743
6751
|
}
|
|
@@ -7331,12 +7339,13 @@ function getHeaderInfo(options) {
|
|
|
7331
7339
|
if (passThrough && crc32 !== UNDEFINED_VALUE) {
|
|
7332
7340
|
rawExtraFieldAES[EXTRAFIELD_OFFSET_AES_VENDOR_VERSION] = VENDOR_VERSION_AE_1;
|
|
7333
7341
|
}
|
|
7334
|
-
rawExtraFieldAES
|
|
7342
|
+
setUint16(getDataView(rawExtraFieldAES), EXTRAFIELD_OFFSET_AES_COMPRESSION_METHOD, compressionMethod);
|
|
7335
7343
|
compressionMethod = COMPRESSION_METHOD_AES;
|
|
7336
7344
|
}
|
|
7337
7345
|
const localExtraFieldZip64Length = writeLocalExtraFieldZip64 ? getLength(rawLocalExtraFieldZip64) : 0;
|
|
7338
7346
|
const extraFieldLength = localExtraFieldZip64Length + getLength(rawExtraFieldAES, rawExtraFieldExtendedTimestamp, rawExtraFieldNTFS, rawExtraFieldUnix, rawExtraField, rawLocalExtraField);
|
|
7339
|
-
|
|
7347
|
+
const maximumUsdzExtraFieldLength = options[OPTION_USDZ] ? EXTRAFIELD_USDZ_MAX_LENGTH : 0;
|
|
7348
|
+
if (extraFieldLength + maximumUsdzExtraFieldLength > MAX_16_BITS) {
|
|
7340
7349
|
throw new Error(ERR_INVALID_EXTRAFIELD_DATA);
|
|
7341
7350
|
}
|
|
7342
7351
|
const dosLastModDate = new Date(Math.ceil(Math.floor(lastModDate.getTime() / 1000) / 2) * 2000);
|
|
@@ -7737,7 +7746,11 @@ async function writeDigitalSignatureRecord(zipWriter, directoryArray, options) {
|
|
|
7737
7746
|
signatureRecord.writeUint32(DIGITAL_SIGNATURE_RECORD_SIGNATURE);
|
|
7738
7747
|
signatureRecord.writeUint16(signatureDataLength);
|
|
7739
7748
|
signatureRecord.writeBytes(signatureData);
|
|
7740
|
-
|
|
7749
|
+
const { writer } = zipWriter;
|
|
7750
|
+
if (exceedsAvailableSize(writer, getLength(signatureRecord.array))) {
|
|
7751
|
+
await writer.closeDisk();
|
|
7752
|
+
}
|
|
7753
|
+
await writeData(writer, signatureRecord.array);
|
|
7741
7754
|
return 6 + signatureDataLength;
|
|
7742
7755
|
}
|
|
7743
7756
|
return 0;
|
|
@@ -7848,7 +7861,7 @@ async function startsWithSplitZipSignature(reader) {
|
|
|
7848
7861
|
return getUint32(getDataView(signatureArray), 0) == SPLIT_ZIP_FILE_SIGNATURE;
|
|
7849
7862
|
}
|
|
7850
7863
|
|
|
7851
|
-
async function copyZipData(zipWriter, reader, entries, directoryOffset
|
|
7864
|
+
async function copyZipData(zipWriter, reader, entries, directoryOffset) {
|
|
7852
7865
|
const { writer } = zipWriter;
|
|
7853
7866
|
const entryPositions = new Map();
|
|
7854
7867
|
if (writer.closeDisk) {
|
|
@@ -7869,9 +7882,10 @@ async function copyZipData(zipWriter, reader, entries, directoryOffset, splitZip
|
|
|
7869
7882
|
}
|
|
7870
7883
|
await copyData(zipWriter, reader, copiedLength, directoryOffset - copiedLength);
|
|
7871
7884
|
} else {
|
|
7885
|
+
const baseOffset = zipWriter.offset;
|
|
7872
7886
|
await copyData(zipWriter, reader, 0, directoryOffset);
|
|
7873
7887
|
entries.forEach(entry => entryPositions.set(entry, {
|
|
7874
|
-
offset:
|
|
7888
|
+
offset: baseOffset + getSourceOffset(reader, entry),
|
|
7875
7889
|
diskNumberStart: 0
|
|
7876
7890
|
}));
|
|
7877
7891
|
}
|