@zip.js/zip.js 2.7.48 → 2.7.49
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 +93 -30
- package/dist/zip-fs-full.min.js +1 -1
- package/dist/zip-fs.js +93 -30
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-full.js +69 -27
- 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 +69 -27
- package/dist/zip.min.js +1 -1
- package/index.cjs +93 -30
- package/index.d.ts +35 -20
- package/index.js +1 -0
- package/index.min.js +1 -1
- package/lib/core/zip-entry.js +1 -1
- package/lib/core/zip-fs-core.js +24 -3
- package/lib/core/zip-reader.js +9 -4
- package/lib/core/zip-writer.js +61 -24
- package/package.json +3 -3
package/lib/core/zip-entry.js
CHANGED
|
@@ -53,7 +53,7 @@ const PROPERTY_NAMES = [
|
|
|
53
53
|
PROPERTY_NAME_MS_DOS_COMPATIBLE, PROPERTY_NAME_ZIP64,
|
|
54
54
|
"directory", "bitFlag", "encrypted", "signature", "filenameUTF8", "commentUTF8", "compressionMethod", "version", "versionMadeBy",
|
|
55
55
|
"extraField", "rawExtraField", "extraFieldZip64", "extraFieldUnicodePath", "extraFieldUnicodeComment", "extraFieldAES", "extraFieldNTFS",
|
|
56
|
-
"extraFieldExtendedTimestamp"];
|
|
56
|
+
"extraFieldExtendedTimestamp", "zipCrypto"];
|
|
57
57
|
|
|
58
58
|
class Entry {
|
|
59
59
|
|
package/lib/core/zip-fs-core.js
CHANGED
|
@@ -72,7 +72,8 @@ class ZipEntry {
|
|
|
72
72
|
id: fs.entries.length,
|
|
73
73
|
parent,
|
|
74
74
|
children: [],
|
|
75
|
-
uncompressedSize: params.uncompressedSize || 0
|
|
75
|
+
uncompressedSize: params.uncompressedSize || 0,
|
|
76
|
+
passThrough: params.passThrough
|
|
76
77
|
});
|
|
77
78
|
fs.entries.push(zipEntry);
|
|
78
79
|
if (parent) {
|
|
@@ -415,7 +416,8 @@ class ZipDirectoryEntry extends ZipEntry {
|
|
|
415
416
|
importedEntries.push(addChild(parent, name, {
|
|
416
417
|
data: entry,
|
|
417
418
|
Reader: getZipBlobReader(Object.assign({}, options)),
|
|
418
|
-
uncompressedSize: entry.uncompressedSize
|
|
419
|
+
uncompressedSize: entry.uncompressedSize,
|
|
420
|
+
passThrough: options.passThrough
|
|
419
421
|
}));
|
|
420
422
|
}
|
|
421
423
|
} catch (error) {
|
|
@@ -732,8 +734,17 @@ async function exportZip(zipWriter, entry, totalSize, options) {
|
|
|
732
734
|
comment,
|
|
733
735
|
lastModDate,
|
|
734
736
|
creationDate,
|
|
735
|
-
lastAccessDate
|
|
737
|
+
lastAccessDate,
|
|
738
|
+
uncompressedSize,
|
|
739
|
+
encrypted,
|
|
740
|
+
zipCrypto,
|
|
741
|
+
signature,
|
|
742
|
+
compressionMethod
|
|
736
743
|
} = child.data;
|
|
744
|
+
let level;
|
|
745
|
+
if (compressionMethod === 0) {
|
|
746
|
+
level = 0;
|
|
747
|
+
}
|
|
737
748
|
zipEntryOptions = {
|
|
738
749
|
externalFileAttribute,
|
|
739
750
|
versionMadeBy,
|
|
@@ -742,6 +753,16 @@ async function exportZip(zipWriter, entry, totalSize, options) {
|
|
|
742
753
|
creationDate,
|
|
743
754
|
lastAccessDate
|
|
744
755
|
};
|
|
756
|
+
if (child.passThrough) {
|
|
757
|
+
zipEntryOptions = Object.assign(zipEntryOptions, {
|
|
758
|
+
passThrough: true,
|
|
759
|
+
encrypted,
|
|
760
|
+
zipCrypto,
|
|
761
|
+
signature,
|
|
762
|
+
uncompressedSize,
|
|
763
|
+
level
|
|
764
|
+
});
|
|
765
|
+
}
|
|
745
766
|
}
|
|
746
767
|
await zipWriter.add(name, child.reader, Object.assign({
|
|
747
768
|
directory: child.directory
|
package/lib/core/zip-reader.js
CHANGED
|
@@ -294,6 +294,7 @@ class ZipReader {
|
|
|
294
294
|
});
|
|
295
295
|
startOffset = Math.max(offsetFileEntry, startOffset);
|
|
296
296
|
await readCommonFooter(fileEntry, fileEntry, directoryView, offset + 6);
|
|
297
|
+
fileEntry.zipCrypto = fileEntry.encrypted && !fileEntry.extraFieldAES;
|
|
297
298
|
const entry = new Entry(fileEntry);
|
|
298
299
|
entry.getData = (writer, options) => fileEntry.getData(writer, entry, options);
|
|
299
300
|
offset = endOffset;
|
|
@@ -428,8 +429,12 @@ class ZipEntry {
|
|
|
428
429
|
lastAccessDate: localDirectory.lastAccessDate,
|
|
429
430
|
creationDate: localDirectory.creationDate
|
|
430
431
|
});
|
|
431
|
-
const
|
|
432
|
+
const passThrough = getOptionValue(zipEntry, options, "passThrough");
|
|
433
|
+
const encrypted = zipEntry.encrypted && localDirectory.encrypted && !passThrough;
|
|
432
434
|
const zipCrypto = encrypted && !extraFieldAES;
|
|
435
|
+
if (!passThrough) {
|
|
436
|
+
fileEntry.zipCrypto = zipCrypto;
|
|
437
|
+
}
|
|
433
438
|
if (encrypted) {
|
|
434
439
|
if (!zipCrypto && extraFieldAES.strength === UNDEFINED_VALUE) {
|
|
435
440
|
throw new Error(ERR_UNSUPPORTED_ENCRYPTION);
|
|
@@ -461,11 +466,11 @@ class ZipEntry {
|
|
|
461
466
|
rawPassword,
|
|
462
467
|
zipCrypto,
|
|
463
468
|
encryptionStrength: extraFieldAES && extraFieldAES.strength,
|
|
464
|
-
signed: getOptionValue(zipEntry, options, "checkSignature"),
|
|
469
|
+
signed: getOptionValue(zipEntry, options, "checkSignature") && !passThrough,
|
|
465
470
|
passwordVerification: zipCrypto && (bitFlag.dataDescriptor ? ((rawLastModDate >>> 8) & 0xFF) : ((signature >>> 24) & 0xFF)),
|
|
466
471
|
signature,
|
|
467
|
-
compressed: compressionMethod != 0,
|
|
468
|
-
encrypted,
|
|
472
|
+
compressed: compressionMethod != 0 && !passThrough,
|
|
473
|
+
encrypted: zipEntry.encrypted && !passThrough,
|
|
469
474
|
useWebWorkers: getOptionValue(zipEntry, options, "useWebWorkers"),
|
|
470
475
|
useCompressionStream: getOptionValue(zipEntry, options, "useCompressionStream"),
|
|
471
476
|
transferStreams: getOptionValue(zipEntry, options, "transferStreams"),
|
package/lib/core/zip-writer.js
CHANGED
|
@@ -98,6 +98,7 @@ const ERR_INVALID_ENCRYPTION_STRENGTH = "The strength must equal 1, 2, or 3";
|
|
|
98
98
|
const ERR_INVALID_EXTRAFIELD_TYPE = "Extra field type exceeds 65535";
|
|
99
99
|
const ERR_INVALID_EXTRAFIELD_DATA = "Extra field data exceeds 64KB";
|
|
100
100
|
const ERR_UNSUPPORTED_FORMAT = "Zip64 is not supported (make sure 'keepOrder' is set to 'true')";
|
|
101
|
+
const ERR_UNDEFINED_UNCOMPRESSED_SIZE = "Undefined uncompressed size";
|
|
101
102
|
|
|
102
103
|
const EXTRAFIELD_DATA_AES = new Uint8Array([0x07, 0x00, 0x02, 0x00, 0x41, 0x45, 0x03, 0x00, 0x00]);
|
|
103
104
|
|
|
@@ -118,7 +119,7 @@ class ZipWriter {
|
|
|
118
119
|
config: getConfiguration(),
|
|
119
120
|
files: new Map(),
|
|
120
121
|
filenames: new Set(),
|
|
121
|
-
offset: writer.writable.size,
|
|
122
|
+
offset: options.offset === UNDEFINED_VALUE ? writer.writable.size : options.offset,
|
|
122
123
|
pendingEntriesSize: 0,
|
|
123
124
|
pendingAddFileCalls: new Set(),
|
|
124
125
|
bufferedWrites: 0
|
|
@@ -214,7 +215,8 @@ export {
|
|
|
214
215
|
ERR_INVALID_EXTRAFIELD_TYPE,
|
|
215
216
|
ERR_INVALID_EXTRAFIELD_DATA,
|
|
216
217
|
ERR_INVALID_ENCRYPTION_STRENGTH,
|
|
217
|
-
ERR_UNSUPPORTED_FORMAT
|
|
218
|
+
ERR_UNSUPPORTED_FORMAT,
|
|
219
|
+
ERR_UNDEFINED_UNCOMPRESSED_SIZE
|
|
218
220
|
};
|
|
219
221
|
|
|
220
222
|
async function addFile(zipWriter, name, reader, options) {
|
|
@@ -254,8 +256,12 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
254
256
|
const msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE, true);
|
|
255
257
|
const internalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE, 0);
|
|
256
258
|
const externalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE, 0);
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
+
const passThrough = getOptionValue(zipWriter, options, "passThrough");
|
|
260
|
+
let password, rawPassword;
|
|
261
|
+
if (!passThrough) {
|
|
262
|
+
password = getOptionValue(zipWriter, options, "password");
|
|
263
|
+
rawPassword = getOptionValue(zipWriter, options, "rawPassword");
|
|
264
|
+
}
|
|
259
265
|
const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength", 3);
|
|
260
266
|
const zipCrypto = getOptionValue(zipWriter, options, "zipCrypto");
|
|
261
267
|
const extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp", true);
|
|
@@ -269,7 +275,7 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
269
275
|
const useCompressionStream = getOptionValue(zipWriter, options, "useCompressionStream");
|
|
270
276
|
let dataDescriptor = getOptionValue(zipWriter, options, "dataDescriptor", true);
|
|
271
277
|
let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
|
|
272
|
-
if (password !== UNDEFINED_VALUE && encryptionStrength !== UNDEFINED_VALUE && (encryptionStrength < 1 || encryptionStrength > 3)) {
|
|
278
|
+
if ((password !== UNDEFINED_VALUE || rawPassword !== UNDEFINED_VALUE) && encryptionStrength !== UNDEFINED_VALUE && (encryptionStrength < 1 || encryptionStrength > 3)) {
|
|
273
279
|
throw new Error(ERR_INVALID_ENCRYPTION_STRENGTH);
|
|
274
280
|
}
|
|
275
281
|
let rawExtraField = new Uint8Array();
|
|
@@ -295,18 +301,28 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
295
301
|
let maximumCompressedSize = 0;
|
|
296
302
|
let maximumEntrySize = 0;
|
|
297
303
|
let uncompressedSize = 0;
|
|
304
|
+
if (passThrough) {
|
|
305
|
+
({ uncompressedSize } = options);
|
|
306
|
+
if (uncompressedSize === UNDEFINED_VALUE) {
|
|
307
|
+
throw new Error(ERR_UNDEFINED_UNCOMPRESSED_SIZE);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
298
310
|
const zip64Enabled = zip64 === true;
|
|
299
311
|
if (reader) {
|
|
300
312
|
reader = initReader(reader);
|
|
301
313
|
await initStream(reader);
|
|
302
|
-
if (
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
zip64
|
|
306
|
-
|
|
314
|
+
if (!passThrough) {
|
|
315
|
+
if (reader.size === UNDEFINED_VALUE) {
|
|
316
|
+
dataDescriptor = true;
|
|
317
|
+
if (zip64 || zip64 === UNDEFINED_VALUE) {
|
|
318
|
+
zip64 = true;
|
|
319
|
+
uncompressedSize = maximumCompressedSize = MAX_32_BITS + 1;
|
|
320
|
+
}
|
|
321
|
+
} else {
|
|
322
|
+
uncompressedSize = reader.size;
|
|
323
|
+
maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
|
|
307
324
|
}
|
|
308
325
|
} else {
|
|
309
|
-
uncompressedSize = reader.size;
|
|
310
326
|
maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
|
|
311
327
|
}
|
|
312
328
|
}
|
|
@@ -324,6 +340,8 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
324
340
|
}
|
|
325
341
|
}
|
|
326
342
|
zip64 = zip64 || false;
|
|
343
|
+
const encrypted = getOptionValue(zipWriter, options, "encrypted");
|
|
344
|
+
const { signature } = options;
|
|
327
345
|
options = Object.assign({}, options, {
|
|
328
346
|
rawFilename,
|
|
329
347
|
rawComment,
|
|
@@ -354,7 +372,10 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
354
372
|
msDosCompatible,
|
|
355
373
|
internalFileAttribute,
|
|
356
374
|
externalFileAttribute,
|
|
357
|
-
useCompressionStream
|
|
375
|
+
useCompressionStream,
|
|
376
|
+
passThrough,
|
|
377
|
+
encrypted: Boolean((password && getLength(password)) || (rawPassword && getLength(rawPassword))) || (passThrough && encrypted),
|
|
378
|
+
signature
|
|
358
379
|
});
|
|
359
380
|
const headerInfo = getHeaderInfo(options);
|
|
360
381
|
const dataDescriptorInfo = getDataDescriptorInfo(options);
|
|
@@ -565,7 +586,8 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
|
|
|
565
586
|
msDosCompatible,
|
|
566
587
|
internalFileAttribute,
|
|
567
588
|
externalFileAttribute,
|
|
568
|
-
useCompressionStream
|
|
589
|
+
useCompressionStream,
|
|
590
|
+
passThrough
|
|
569
591
|
} = options;
|
|
570
592
|
const fileEntry = {
|
|
571
593
|
lock,
|
|
@@ -586,9 +608,14 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
|
|
|
586
608
|
externalFileAttribute,
|
|
587
609
|
diskNumberStart
|
|
588
610
|
};
|
|
611
|
+
let {
|
|
612
|
+
signature,
|
|
613
|
+
uncompressedSize
|
|
614
|
+
} = options;
|
|
589
615
|
let compressedSize = 0;
|
|
590
|
-
|
|
591
|
-
|
|
616
|
+
if (!passThrough) {
|
|
617
|
+
uncompressedSize = 0;
|
|
618
|
+
}
|
|
592
619
|
const { writable } = writer;
|
|
593
620
|
if (reader) {
|
|
594
621
|
reader.chunkSize = getChunkSize(config);
|
|
@@ -604,9 +631,9 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
|
|
|
604
631
|
encryptionStrength,
|
|
605
632
|
zipCrypto: encrypted && zipCrypto,
|
|
606
633
|
passwordVerification: encrypted && zipCrypto && (rawLastModDate >> 8) & 0xFF,
|
|
607
|
-
signed:
|
|
608
|
-
compressed,
|
|
609
|
-
encrypted,
|
|
634
|
+
signed: !passThrough,
|
|
635
|
+
compressed: compressed && !passThrough,
|
|
636
|
+
encrypted: encrypted && !passThrough,
|
|
610
637
|
useWebWorkers,
|
|
611
638
|
useCompressionStream,
|
|
612
639
|
transferStreams: false
|
|
@@ -615,9 +642,11 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
|
|
|
615
642
|
streamOptions: { signal, size, onstart, onprogress, onend }
|
|
616
643
|
};
|
|
617
644
|
const result = await runWorker({ readable, writable }, workerOptions);
|
|
618
|
-
uncompressedSize = result.inputSize;
|
|
619
645
|
compressedSize = result.outputSize;
|
|
620
|
-
|
|
646
|
+
if (!passThrough) {
|
|
647
|
+
uncompressedSize = result.inputSize;
|
|
648
|
+
signature = result.signature;
|
|
649
|
+
}
|
|
621
650
|
writable.size += uncompressedSize;
|
|
622
651
|
} else {
|
|
623
652
|
await writeData(writable, localHeaderArray);
|
|
@@ -660,6 +689,7 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
|
|
|
660
689
|
creationDate,
|
|
661
690
|
lastAccessDate,
|
|
662
691
|
encrypted,
|
|
692
|
+
zipCrypto,
|
|
663
693
|
size: metadataSize + compressedSize,
|
|
664
694
|
compressionMethod,
|
|
665
695
|
version,
|
|
@@ -681,8 +711,6 @@ function getHeaderInfo(options) {
|
|
|
681
711
|
lastModDate,
|
|
682
712
|
lastAccessDate,
|
|
683
713
|
creationDate,
|
|
684
|
-
rawPassword,
|
|
685
|
-
password,
|
|
686
714
|
level,
|
|
687
715
|
zip64,
|
|
688
716
|
zipCrypto,
|
|
@@ -691,10 +719,10 @@ function getHeaderInfo(options) {
|
|
|
691
719
|
directory,
|
|
692
720
|
rawExtraField,
|
|
693
721
|
encryptionStrength,
|
|
694
|
-
extendedTimestamp
|
|
722
|
+
extendedTimestamp,
|
|
723
|
+
encrypted
|
|
695
724
|
} = options;
|
|
696
725
|
const compressed = level !== 0 && !directory;
|
|
697
|
-
const encrypted = Boolean((password && getLength(password)) || (rawPassword && getLength(rawPassword)));
|
|
698
726
|
let version = options.version;
|
|
699
727
|
let rawExtraFieldAES;
|
|
700
728
|
if (encrypted && !zipCrypto) {
|
|
@@ -753,6 +781,15 @@ function getHeaderInfo(options) {
|
|
|
753
781
|
let compressionMethod = COMPRESSION_METHOD_STORE;
|
|
754
782
|
if (compressed) {
|
|
755
783
|
compressionMethod = COMPRESSION_METHOD_DEFLATE;
|
|
784
|
+
if (level >= 1 && level < 3) {
|
|
785
|
+
bitFlag = bitFlag | 0b110;
|
|
786
|
+
}
|
|
787
|
+
if (level >= 3 && level < 5) {
|
|
788
|
+
bitFlag = bitFlag | 0b01;
|
|
789
|
+
}
|
|
790
|
+
if (level === 9) {
|
|
791
|
+
bitFlag = bitFlag | 0b10;
|
|
792
|
+
}
|
|
756
793
|
}
|
|
757
794
|
if (zip64) {
|
|
758
795
|
version = version > VERSION_ZIP64 ? version : VERSION_ZIP64;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "A JavaScript library to zip and unzip files in the browser, Deno and Node.js",
|
|
4
4
|
"author": "Gildas Lormeau",
|
|
5
5
|
"license": "BSD-3-Clause",
|
|
6
|
-
"version": "2.7.
|
|
6
|
+
"version": "2.7.49",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"keywords": [
|
|
9
9
|
"zip",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"@rollup/plugin-replace": "^5.0.7",
|
|
81
81
|
"@rollup/plugin-terser": "^0.4.4",
|
|
82
82
|
"http-server": "^14.1.1",
|
|
83
|
-
"rollup": "^4.
|
|
84
|
-
"typedoc": "^0.26.
|
|
83
|
+
"rollup": "^4.21.0",
|
|
84
|
+
"typedoc": "^0.26.6"
|
|
85
85
|
}
|
|
86
86
|
}
|