@zip.js/zip.js 2.7.50 → 2.7.52
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-fs-full.js +36 -26
- package/dist/zip-fs-full.min.js +1 -1
- package/dist/zip-fs.js +36 -26
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-full.js +24 -20
- package/dist/zip-full.min.js +1 -1
- package/dist/zip-no-worker-deflate.min.js +1 -1
- package/dist/zip-no-worker-inflate.min.js +1 -1
- package/dist/zip-no-worker.min.js +1 -1
- package/dist/zip.js +24 -20
- package/dist/zip.min.js +1 -1
- package/index.cjs +36 -26
- package/index.d.ts +11 -3
- package/index.min.js +1 -1
- package/lib/core/zip-entry.js +11 -4
- package/lib/core/zip-fs-core.js +12 -6
- package/lib/core/zip-reader.js +3 -3
- package/lib/core/zip-writer.js +18 -13
- package/package.json +1 -1
package/lib/core/zip-entry.js
CHANGED
|
@@ -44,16 +44,19 @@ const PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE = "internalFileAttribute";
|
|
|
44
44
|
const PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE = "externalFileAttribute";
|
|
45
45
|
const PROPERTY_NAME_MS_DOS_COMPATIBLE = "msDosCompatible";
|
|
46
46
|
const PROPERTY_NAME_ZIP64 = "zip64";
|
|
47
|
+
const PROPERTY_NAME_ENCRYPTED = "encrypted";
|
|
48
|
+
const PROPERTY_NAME_VERSION = "version";
|
|
49
|
+
const PROPERTY_NAME_VERSION_MADE_BY = "versionMadeBy";
|
|
50
|
+
const PROPERTY_NAME_ZIPCRYPTO = "zipCrypto";
|
|
47
51
|
|
|
48
52
|
const PROPERTY_NAMES = [
|
|
49
53
|
PROPERTY_NAME_FILENAME, PROPERTY_NAME_RAW_FILENAME, PROPERTY_NAME_COMPPRESSED_SIZE, PROPERTY_NAME_UNCOMPPRESSED_SIZE,
|
|
50
54
|
PROPERTY_NAME_LAST_MODIFICATION_DATE, PROPERTY_NAME_RAW_LAST_MODIFICATION_DATE, PROPERTY_NAME_COMMENT, PROPERTY_NAME_RAW_COMMENT,
|
|
51
55
|
PROPERTY_NAME_LAST_ACCESS_DATE, PROPERTY_NAME_CREATION_DATE, PROPERTY_NAME_OFFSET, PROPERTY_NAME_DISK_NUMBER_START,
|
|
52
56
|
PROPERTY_NAME_DISK_NUMBER_START, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE,
|
|
53
|
-
PROPERTY_NAME_MS_DOS_COMPATIBLE, PROPERTY_NAME_ZIP64,
|
|
54
|
-
"directory", "bitFlag", "
|
|
55
|
-
"
|
|
56
|
-
"extraFieldExtendedTimestamp", "zipCrypto"];
|
|
57
|
+
PROPERTY_NAME_MS_DOS_COMPATIBLE, PROPERTY_NAME_ZIP64, PROPERTY_NAME_ENCRYPTED, PROPERTY_NAME_VERSION, PROPERTY_NAME_VERSION_MADE_BY,
|
|
58
|
+
PROPERTY_NAME_ZIPCRYPTO, "directory", "bitFlag", "signature", "filenameUTF8", "commentUTF8", "compressionMethod", "extraField", "rawExtraField",
|
|
59
|
+
"extraFieldZip64", "extraFieldUnicodePath", "extraFieldUnicodeComment", "extraFieldAES", "extraFieldNTFS", "extraFieldExtendedTimestamp"];
|
|
57
60
|
|
|
58
61
|
class Entry {
|
|
59
62
|
|
|
@@ -82,5 +85,9 @@ export {
|
|
|
82
85
|
PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE,
|
|
83
86
|
PROPERTY_NAME_MS_DOS_COMPATIBLE,
|
|
84
87
|
PROPERTY_NAME_ZIP64,
|
|
88
|
+
PROPERTY_NAME_ENCRYPTED,
|
|
89
|
+
PROPERTY_NAME_VERSION,
|
|
90
|
+
PROPERTY_NAME_VERSION_MADE_BY,
|
|
91
|
+
PROPERTY_NAME_ZIPCRYPTO,
|
|
85
92
|
Entry
|
|
86
93
|
};
|
package/lib/core/zip-fs-core.js
CHANGED
|
@@ -739,12 +739,9 @@ async function exportZip(zipWriter, entry, totalSize, options) {
|
|
|
739
739
|
encrypted,
|
|
740
740
|
zipCrypto,
|
|
741
741
|
signature,
|
|
742
|
-
compressionMethod
|
|
742
|
+
compressionMethod,
|
|
743
|
+
extraFieldAES
|
|
743
744
|
} = child.data;
|
|
744
|
-
let level;
|
|
745
|
-
if (compressionMethod === 0) {
|
|
746
|
-
level = 0;
|
|
747
|
-
}
|
|
748
745
|
zipEntryOptions = {
|
|
749
746
|
externalFileAttribute,
|
|
750
747
|
versionMadeBy,
|
|
@@ -754,13 +751,22 @@ async function exportZip(zipWriter, entry, totalSize, options) {
|
|
|
754
751
|
lastAccessDate
|
|
755
752
|
};
|
|
756
753
|
if (child.passThrough) {
|
|
754
|
+
let level, encryptionStrength;
|
|
755
|
+
if (compressionMethod === 0) {
|
|
756
|
+
level = 0;
|
|
757
|
+
}
|
|
758
|
+
if (extraFieldAES) {
|
|
759
|
+
encryptionStrength = extraFieldAES.strength;
|
|
760
|
+
}
|
|
757
761
|
zipEntryOptions = Object.assign(zipEntryOptions, {
|
|
758
762
|
passThrough: true,
|
|
759
763
|
encrypted,
|
|
760
764
|
zipCrypto,
|
|
761
765
|
signature,
|
|
762
766
|
uncompressedSize,
|
|
763
|
-
level
|
|
767
|
+
level,
|
|
768
|
+
encryptionStrength,
|
|
769
|
+
compressionMethod
|
|
764
770
|
});
|
|
765
771
|
}
|
|
766
772
|
}
|
package/lib/core/zip-reader.js
CHANGED
|
@@ -407,6 +407,7 @@ class ZipEntry {
|
|
|
407
407
|
const dataView = getDataView(dataArray);
|
|
408
408
|
let password = getOptionValue(zipEntry, options, "password");
|
|
409
409
|
let rawPassword = getOptionValue(zipEntry, options, "rawPassword");
|
|
410
|
+
const passThrough = getOptionValue(zipEntry, options, "passThrough");
|
|
410
411
|
password = password && password.length && password;
|
|
411
412
|
rawPassword = rawPassword && rawPassword.length && rawPassword;
|
|
412
413
|
if (extraFieldAES) {
|
|
@@ -414,7 +415,7 @@ class ZipEntry {
|
|
|
414
415
|
throw new Error(ERR_UNSUPPORTED_COMPRESSION);
|
|
415
416
|
}
|
|
416
417
|
}
|
|
417
|
-
if (compressionMethod != COMPRESSION_METHOD_STORE && compressionMethod != COMPRESSION_METHOD_DEFLATE) {
|
|
418
|
+
if ((compressionMethod != COMPRESSION_METHOD_STORE && compressionMethod != COMPRESSION_METHOD_DEFLATE) && !passThrough) {
|
|
418
419
|
throw new Error(ERR_UNSUPPORTED_COMPRESSION);
|
|
419
420
|
}
|
|
420
421
|
if (getUint32(dataView, 0) != LOCAL_FILE_HEADER_SIGNATURE) {
|
|
@@ -429,7 +430,6 @@ class ZipEntry {
|
|
|
429
430
|
lastAccessDate: localDirectory.lastAccessDate,
|
|
430
431
|
creationDate: localDirectory.creationDate
|
|
431
432
|
});
|
|
432
|
-
const passThrough = getOptionValue(zipEntry, options, "passThrough");
|
|
433
433
|
const encrypted = zipEntry.encrypted && localDirectory.encrypted && !passThrough;
|
|
434
434
|
const zipCrypto = encrypted && !extraFieldAES;
|
|
435
435
|
if (!passThrough) {
|
|
@@ -456,7 +456,7 @@ class ZipEntry {
|
|
|
456
456
|
writer = new WritableStream();
|
|
457
457
|
}
|
|
458
458
|
writer = initWriter(writer);
|
|
459
|
-
await initStream(writer, uncompressedSize);
|
|
459
|
+
await initStream(writer, passThrough ? compressedSize : uncompressedSize);
|
|
460
460
|
const { writable } = writer;
|
|
461
461
|
const { onstart, onprogress, onend } = options;
|
|
462
462
|
const workerOptions = {
|
package/lib/core/zip-writer.js
CHANGED
|
@@ -86,6 +86,10 @@ import {
|
|
|
86
86
|
PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE,
|
|
87
87
|
PROPERTY_NAME_MS_DOS_COMPATIBLE,
|
|
88
88
|
PROPERTY_NAME_ZIP64,
|
|
89
|
+
PROPERTY_NAME_ENCRYPTED,
|
|
90
|
+
PROPERTY_NAME_VERSION,
|
|
91
|
+
PROPERTY_NAME_VERSION_MADE_BY,
|
|
92
|
+
PROPERTY_NAME_ZIPCRYPTO,
|
|
89
93
|
Entry
|
|
90
94
|
} from "./zip-entry.js";
|
|
91
95
|
|
|
@@ -242,11 +246,11 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
242
246
|
if (getLength(rawComment) > MAX_16_BITS) {
|
|
243
247
|
throw new Error(ERR_INVALID_ENTRY_COMMENT);
|
|
244
248
|
}
|
|
245
|
-
const version = getOptionValue(zipWriter, options,
|
|
249
|
+
const version = getOptionValue(zipWriter, options, PROPERTY_NAME_VERSION, VERSION_DEFLATE);
|
|
246
250
|
if (version > MAX_16_BITS) {
|
|
247
251
|
throw new Error(ERR_INVALID_VERSION);
|
|
248
252
|
}
|
|
249
|
-
const versionMadeBy = getOptionValue(zipWriter, options,
|
|
253
|
+
const versionMadeBy = getOptionValue(zipWriter, options, PROPERTY_NAME_VERSION_MADE_BY, 20);
|
|
250
254
|
if (versionMadeBy > MAX_16_BITS) {
|
|
251
255
|
throw new Error(ERR_INVALID_VERSION);
|
|
252
256
|
}
|
|
@@ -263,7 +267,7 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
263
267
|
rawPassword = getOptionValue(zipWriter, options, "rawPassword");
|
|
264
268
|
}
|
|
265
269
|
const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength", 3);
|
|
266
|
-
const zipCrypto = getOptionValue(zipWriter, options,
|
|
270
|
+
const zipCrypto = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIPCRYPTO);
|
|
267
271
|
const extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp", true);
|
|
268
272
|
const keepOrder = getOptionValue(zipWriter, options, "keepOrder", true);
|
|
269
273
|
const level = getOptionValue(zipWriter, options, "level");
|
|
@@ -273,9 +277,10 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
273
277
|
const signal = getOptionValue(zipWriter, options, "signal");
|
|
274
278
|
const useUnicodeFileNames = getOptionValue(zipWriter, options, "useUnicodeFileNames", true);
|
|
275
279
|
const useCompressionStream = getOptionValue(zipWriter, options, "useCompressionStream");
|
|
280
|
+
const compressionMethod = getOptionValue(zipWriter, options, "compressionMethod");
|
|
276
281
|
let dataDescriptor = getOptionValue(zipWriter, options, "dataDescriptor", true);
|
|
277
282
|
let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
|
|
278
|
-
if ((password !== UNDEFINED_VALUE || rawPassword !== UNDEFINED_VALUE) &&
|
|
283
|
+
if (!zipCrypto && (password !== UNDEFINED_VALUE || rawPassword !== UNDEFINED_VALUE) && !(encryptionStrength >= 1 && encryptionStrength <= 3)) {
|
|
279
284
|
throw new Error(ERR_INVALID_ENCRYPTION_STRENGTH);
|
|
280
285
|
}
|
|
281
286
|
let rawExtraField = new Uint8Array();
|
|
@@ -340,7 +345,7 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
340
345
|
}
|
|
341
346
|
}
|
|
342
347
|
zip64 = zip64 || false;
|
|
343
|
-
const encrypted = getOptionValue(zipWriter, options,
|
|
348
|
+
const encrypted = getOptionValue(zipWriter, options, PROPERTY_NAME_ENCRYPTED);
|
|
344
349
|
const { signature } = options;
|
|
345
350
|
options = Object.assign({}, options, {
|
|
346
351
|
rawFilename,
|
|
@@ -375,7 +380,8 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
375
380
|
useCompressionStream,
|
|
376
381
|
passThrough,
|
|
377
382
|
encrypted: Boolean((password && getLength(password)) || (rawPassword && getLength(rawPassword))) || (passThrough && encrypted),
|
|
378
|
-
signature
|
|
383
|
+
signature,
|
|
384
|
+
compressionMethod
|
|
379
385
|
});
|
|
380
386
|
const headerInfo = getHeaderInfo(options);
|
|
381
387
|
const dataDescriptorInfo = getDataDescriptorInfo(options);
|
|
@@ -723,7 +729,7 @@ function getHeaderInfo(options) {
|
|
|
723
729
|
encrypted
|
|
724
730
|
} = options;
|
|
725
731
|
const compressed = level !== 0 && !directory;
|
|
726
|
-
let version = options
|
|
732
|
+
let { version, compressionMethod } = options;
|
|
727
733
|
let rawExtraFieldAES;
|
|
728
734
|
if (encrypted && !zipCrypto) {
|
|
729
735
|
rawExtraFieldAES = new Uint8Array(getLength(EXTRAFIELD_DATA_AES) + 2);
|
|
@@ -778,9 +784,10 @@ function getHeaderInfo(options) {
|
|
|
778
784
|
if (dataDescriptor) {
|
|
779
785
|
bitFlag = bitFlag | BITFLAG_DATA_DESCRIPTOR;
|
|
780
786
|
}
|
|
781
|
-
|
|
787
|
+
if (compressionMethod === UNDEFINED_VALUE) {
|
|
788
|
+
compressionMethod = compressed ? COMPRESSION_METHOD_DEFLATE : COMPRESSION_METHOD_STORE;
|
|
789
|
+
}
|
|
782
790
|
if (compressed) {
|
|
783
|
-
compressionMethod = COMPRESSION_METHOD_DEFLATE;
|
|
784
791
|
if (level >= 1 && level < 3) {
|
|
785
792
|
bitFlag = bitFlag | 0b110;
|
|
786
793
|
}
|
|
@@ -798,10 +805,8 @@ function getHeaderInfo(options) {
|
|
|
798
805
|
bitFlag = bitFlag | BITFLAG_ENCRYPTED;
|
|
799
806
|
if (!zipCrypto) {
|
|
800
807
|
version = version > VERSION_AES ? version : VERSION_AES;
|
|
808
|
+
rawExtraFieldAES[9] = compressionMethod;
|
|
801
809
|
compressionMethod = COMPRESSION_METHOD_AES;
|
|
802
|
-
if (compressed) {
|
|
803
|
-
rawExtraFieldAES[9] = COMPRESSION_METHOD_DEFLATE;
|
|
804
|
-
}
|
|
805
810
|
}
|
|
806
811
|
}
|
|
807
812
|
const headerArray = new Uint8Array(26);
|
|
@@ -1116,7 +1121,7 @@ async function closeFile(zipWriter, comment, options) {
|
|
|
1116
1121
|
if (availableSize < END_OF_CENTRAL_DIR_LENGTH) {
|
|
1117
1122
|
lastDiskNumber++;
|
|
1118
1123
|
}
|
|
1119
|
-
let zip64 = getOptionValue(zipWriter, options,
|
|
1124
|
+
let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
|
|
1120
1125
|
if (directoryOffset > MAX_32_BITS || directoryDataLength > MAX_32_BITS || filesLength > MAX_16_BITS || lastDiskNumber > MAX_16_BITS) {
|
|
1121
1126
|
if (zip64 === false) {
|
|
1122
1127
|
throw new Error(ERR_UNSUPPORTED_FORMAT);
|
package/package.json
CHANGED