@zip.js/zip.js 2.8.38 → 2.8.41
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/README.md +0 -12
- package/deno.json +1 -1
- package/dist/zip-core.js +115 -29
- package/dist/zip-core.min.js +1 -1
- package/dist/zip-fs-core.js +115 -29
- package/dist/zip-fs-core.min.js +1 -1
- package/dist/zip-fs-native.js +116 -30
- package/dist/zip-fs-native.min.js +1 -1
- package/dist/zip-fs.js +116 -30
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-legacy.js +116 -30
- package/dist/zip-legacy.min.js +1 -1
- package/dist/zip-native.js +116 -30
- package/dist/zip-native.min.js +1 -1
- package/dist/zip-web-worker-native.js +1 -1
- package/dist/zip-web-worker.js +1 -1
- package/dist/zip.js +116 -30
- package/dist/zip.min.js +1 -1
- package/index-native.cjs +116 -30
- package/index-native.min.js +1 -1
- package/index.cjs +116 -30
- package/index.d.cts +11 -2
- package/index.d.ts +11 -2
- package/index.min.js +1 -1
- package/lib/core/codec-registry.js +1 -1
- package/lib/core/io.js +28 -12
- package/lib/core/streams/zip-crypto-stream.js +1 -1
- package/lib/core/streams/zip-entry-stream.js +6 -5
- package/lib/core/util/compatible-streams.js +72 -0
- package/lib/core/web-worker-inline-native.js +1 -1
- package/lib/core/web-worker-inline-wasm.js +1 -1
- package/lib/core/zip-reader.js +12 -8
- package/lib/core/zip-writer.js +4 -2
- package/package.json +4 -2
- package/worker-message-property-names.js +1 -1
package/README.md
CHANGED
|
@@ -14,18 +14,6 @@ See https://gildas-lormeau.github.io/zip-manager
|
|
|
14
14
|
|
|
15
15
|
See here for more info: https://gildas-lormeau.github.io/zip.js/
|
|
16
16
|
|
|
17
|
-
# Bundle size
|
|
18
|
-
|
|
19
|
-
zip.js is tree-shakeable: import named identifiers and your bundler removes what you do
|
|
20
|
-
not use, e.g. the whole write path if you only read zip files. `import * as zip from
|
|
21
|
-
"@zip.js/zip.js"` keeps everything.
|
|
22
|
-
|
|
23
|
-
Smaller entry points are also available, e.g. `@zip.js/zip.js/lib/zip-core.js` embeds
|
|
24
|
-
neither the Web Worker code nor the WASM module, pass `workerURI` and `wasmURI` to
|
|
25
|
-
`configure()` instead. The prebuilt bundles in
|
|
26
|
-
[`/dist`](https://github.com/gildas-lormeau/zip.js/tree/master/dist) are standalone files
|
|
27
|
-
for script tags and AMD loaders, they are not tree-shaken.
|
|
28
|
-
|
|
29
17
|
# Examples
|
|
30
18
|
|
|
31
19
|
## Hello world
|
package/deno.json
CHANGED
package/dist/zip-core.js
CHANGED
|
@@ -317,7 +317,7 @@
|
|
|
317
317
|
|
|
318
318
|
async function ensureCodecStreams(format, codecURI) {
|
|
319
319
|
if (!codecStreams.has(format) && codecURI) {
|
|
320
|
-
setCodecStreams(format, await import(codecURI));
|
|
320
|
+
setCodecStreams(format, await import(/* webpackIgnore: true */ /* @vite-ignore */ codecURI));
|
|
321
321
|
}
|
|
322
322
|
}
|
|
323
323
|
|
|
@@ -1714,7 +1714,7 @@
|
|
|
1714
1714
|
if (zipCrypto.password || zipCrypto.rawPassword) {
|
|
1715
1715
|
const decryptedHeader = decrypt(zipCrypto, chunk.subarray(0, HEADER_LENGTH));
|
|
1716
1716
|
zipCrypto.password = zipCrypto.rawPassword = null;
|
|
1717
|
-
if ((decryptedHeader
|
|
1717
|
+
if ((decryptedHeader[HEADER_LENGTH - 1] ^ zipCrypto.passwordVerification) != 0) {
|
|
1718
1718
|
throw new Error(ERR_INVALID_PASSWORD);
|
|
1719
1719
|
}
|
|
1720
1720
|
chunk = chunk.subarray(HEADER_LENGTH);
|
|
@@ -1826,6 +1826,73 @@
|
|
|
1826
1826
|
return number & 0xFFFFFFFF;
|
|
1827
1827
|
}
|
|
1828
1828
|
|
|
1829
|
+
/*
|
|
1830
|
+
Copyright (c) 2026 Gildas Lormeau. All rights reserved.
|
|
1831
|
+
|
|
1832
|
+
Redistribution and use in source and binary forms, with or without
|
|
1833
|
+
modification, are permitted provided that the following conditions are met:
|
|
1834
|
+
|
|
1835
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
1836
|
+
this list of conditions and the following disclaimer.
|
|
1837
|
+
|
|
1838
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
1839
|
+
notice, this list of conditions and the following disclaimer in
|
|
1840
|
+
the documentation and/or other materials provided with the distribution.
|
|
1841
|
+
|
|
1842
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
1843
|
+
derived from this software without specific prior written permission.
|
|
1844
|
+
|
|
1845
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
1846
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
1847
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
1848
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
1849
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
1850
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
1851
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
1852
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
1853
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
1854
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1855
|
+
*/
|
|
1856
|
+
|
|
1857
|
+
|
|
1858
|
+
function toCompatibleReadable(readable) {
|
|
1859
|
+
if (readable instanceof ReadableStream) {
|
|
1860
|
+
return readable;
|
|
1861
|
+
}
|
|
1862
|
+
const reader = readable.getReader();
|
|
1863
|
+
return new ReadableStream({
|
|
1864
|
+
async pull(controller) {
|
|
1865
|
+
const { value, done } = await reader.read();
|
|
1866
|
+
if (done) {
|
|
1867
|
+
controller.close();
|
|
1868
|
+
} else {
|
|
1869
|
+
controller.enqueue(value);
|
|
1870
|
+
}
|
|
1871
|
+
},
|
|
1872
|
+
cancel(reason) {
|
|
1873
|
+
return reader.cancel(reason);
|
|
1874
|
+
}
|
|
1875
|
+
});
|
|
1876
|
+
}
|
|
1877
|
+
|
|
1878
|
+
function toCompatibleWritable(writable) {
|
|
1879
|
+
if (writable instanceof WritableStream) {
|
|
1880
|
+
return writable;
|
|
1881
|
+
}
|
|
1882
|
+
const writer = writable.getWriter();
|
|
1883
|
+
return new WritableStream({
|
|
1884
|
+
write(chunk) {
|
|
1885
|
+
return writer.write(chunk);
|
|
1886
|
+
},
|
|
1887
|
+
close() {
|
|
1888
|
+
return writer.close();
|
|
1889
|
+
},
|
|
1890
|
+
abort(reason) {
|
|
1891
|
+
return writer.abort(reason);
|
|
1892
|
+
}
|
|
1893
|
+
});
|
|
1894
|
+
}
|
|
1895
|
+
|
|
1829
1896
|
/*
|
|
1830
1897
|
Copyright (c) 2025 Gildas Lormeau. All rights reserved.
|
|
1831
1898
|
|
|
@@ -1868,7 +1935,7 @@
|
|
|
1868
1935
|
|
|
1869
1936
|
constructor(options, { chunkSize, CompressionStreamZlib, CompressionStream }) {
|
|
1870
1937
|
super({});
|
|
1871
|
-
const { compressed, encrypted, useCompressionStream, zipCrypto, signed, level, deflate64, format } = options;
|
|
1938
|
+
const { compressed, encrypted, useCompressionStream, zipCrypto, signed, level, deflate64, format, compressionMethod } = options;
|
|
1872
1939
|
const stream = this;
|
|
1873
1940
|
let crc32Stream, encryptionStream, gzipCrc32Stream;
|
|
1874
1941
|
let readable = super.readable;
|
|
@@ -1881,7 +1948,7 @@
|
|
|
1881
1948
|
}
|
|
1882
1949
|
if (compressed) {
|
|
1883
1950
|
if (codecStreams) {
|
|
1884
|
-
readable = pipeThroughBackpressured(readable, createCodecStream(codecStreams.CompressionStream, format, { level, chunkSize }));
|
|
1951
|
+
readable = pipeThroughBackpressured(readable, createCodecStream(codecStreams.CompressionStream, format, { level, chunkSize, compressionMethod }));
|
|
1885
1952
|
} else if (useGzipCrc32) {
|
|
1886
1953
|
gzipCrc32Stream = new GzipToRawDeflateStream();
|
|
1887
1954
|
readable = pipeThroughBackpressured(readable, new CompressionStream(FORMAT_GZIP));
|
|
@@ -1956,7 +2023,7 @@
|
|
|
1956
2023
|
|
|
1957
2024
|
constructor(options, { chunkSize, DecompressionStreamZlib, DecompressionStream }) {
|
|
1958
2025
|
super({});
|
|
1959
|
-
const { zipCrypto, encrypted, signed, signature, compressed, useCompressionStream, deflate64, format } = options;
|
|
2026
|
+
const { zipCrypto, encrypted, signed, signature, compressed, useCompressionStream, deflate64, format, compressionMethod, rawBitFlag, outputSize } = options;
|
|
1960
2027
|
let crc32Stream, decryptionStream;
|
|
1961
2028
|
let readable = super.readable;
|
|
1962
2029
|
if (encrypted) {
|
|
@@ -1970,7 +2037,7 @@
|
|
|
1970
2037
|
if (compressed) {
|
|
1971
2038
|
const codecStreams = format && getCodecStreams(format);
|
|
1972
2039
|
if (codecStreams) {
|
|
1973
|
-
readable = pipeThroughBackpressured(readable, createCodecStream(codecStreams.DecompressionStream, format, { chunkSize }));
|
|
2040
|
+
readable = pipeThroughBackpressured(readable, createCodecStream(codecStreams.DecompressionStream, format, { chunkSize, compressionMethod, rawBitFlag, uncompressedSize: outputSize }));
|
|
1974
2041
|
} else {
|
|
1975
2042
|
readable = pipeThroughCompressionStream(readable, useCompressionStream, { chunkSize, deflate64 }, DecompressionStream, DecompressionStreamZlib);
|
|
1976
2043
|
}
|
|
@@ -2045,7 +2112,7 @@
|
|
|
2045
2112
|
}
|
|
2046
2113
|
|
|
2047
2114
|
function pipeThrough(readable, transformStream) {
|
|
2048
|
-
return readable.pipeThrough(transformStream);
|
|
2115
|
+
return toCompatibleReadable(readable).pipeThrough(transformStream);
|
|
2049
2116
|
}
|
|
2050
2117
|
|
|
2051
2118
|
function pipeThroughBackpressured(readable, transformStream) {
|
|
@@ -3186,10 +3253,10 @@
|
|
|
3186
3253
|
const { blob, size } = reader;
|
|
3187
3254
|
const { offset = 0, size: readSize = size - offset } = options || {};
|
|
3188
3255
|
if (!offset && readSize >= size) {
|
|
3189
|
-
return blob.stream();
|
|
3256
|
+
return toCompatibleReadable(blob.stream());
|
|
3190
3257
|
}
|
|
3191
3258
|
if (blobSliceReliable) {
|
|
3192
|
-
return blob.slice(offset, offset + readSize).stream();
|
|
3259
|
+
return toCompatibleReadable(blob.slice(offset, offset + readSize).stream());
|
|
3193
3260
|
}
|
|
3194
3261
|
return super.createReadable(options);
|
|
3195
3262
|
}
|
|
@@ -3208,22 +3275,37 @@
|
|
|
3208
3275
|
}
|
|
3209
3276
|
}
|
|
3210
3277
|
|
|
3278
|
+
function responseSupportsGlobalReadable() {
|
|
3279
|
+
return typeof Blob.prototype.stream != FUNCTION_TYPE || new Blob([]).stream() instanceof ReadableStream;
|
|
3280
|
+
}
|
|
3281
|
+
|
|
3211
3282
|
class BlobWriter extends Stream {
|
|
3212
3283
|
|
|
3213
3284
|
constructor(contentType) {
|
|
3214
3285
|
super();
|
|
3215
3286
|
const writer = this;
|
|
3216
3287
|
const transformStream = new TransformStream();
|
|
3217
|
-
const headers = [];
|
|
3218
|
-
if (contentType) {
|
|
3219
|
-
headers.push([HTTP_HEADER_CONTENT_TYPE, contentType]);
|
|
3220
|
-
}
|
|
3221
3288
|
Object.defineProperty(writer, PROPERTY_NAME_WRITABLE, {
|
|
3222
3289
|
get() {
|
|
3223
3290
|
return transformStream.writable;
|
|
3224
3291
|
}
|
|
3225
3292
|
});
|
|
3226
|
-
|
|
3293
|
+
if (responseSupportsGlobalReadable()) {
|
|
3294
|
+
const headers = [];
|
|
3295
|
+
if (contentType) {
|
|
3296
|
+
headers.push([HTTP_HEADER_CONTENT_TYPE, contentType]);
|
|
3297
|
+
}
|
|
3298
|
+
writer.blob = new Response(transformStream.readable, { headers }).blob();
|
|
3299
|
+
} else {
|
|
3300
|
+
const chunks = [];
|
|
3301
|
+
writer.blob = transformStream.readable
|
|
3302
|
+
.pipeTo(new WritableStream({
|
|
3303
|
+
write(chunk) {
|
|
3304
|
+
chunks.push(chunk);
|
|
3305
|
+
}
|
|
3306
|
+
}))
|
|
3307
|
+
.then(() => new Blob(chunks, { type: contentType }));
|
|
3308
|
+
}
|
|
3227
3309
|
writer.blob.catch(() => { });
|
|
3228
3310
|
}
|
|
3229
3311
|
|
|
@@ -3736,7 +3818,7 @@
|
|
|
3736
3818
|
|
|
3737
3819
|
getDiskOffset(diskNumber) {
|
|
3738
3820
|
const { diskOffsets, size } = this;
|
|
3739
|
-
const diskOffset = diskOffsets
|
|
3821
|
+
const diskOffset = diskOffsets[diskNumber];
|
|
3740
3822
|
return diskOffset === UNDEFINED_VALUE ? size : diskOffset;
|
|
3741
3823
|
}
|
|
3742
3824
|
|
|
@@ -3875,9 +3957,9 @@
|
|
|
3875
3957
|
if (Array.isArray(reader)) {
|
|
3876
3958
|
reader = new SplitDataReader(reader);
|
|
3877
3959
|
}
|
|
3878
|
-
if (reader instanceof ReadableStream) {
|
|
3960
|
+
if (reader instanceof ReadableStream || typeof reader.getReader == FUNCTION_TYPE) {
|
|
3879
3961
|
reader = {
|
|
3880
|
-
readable: reader
|
|
3962
|
+
readable: toCompatibleReadable(reader)
|
|
3881
3963
|
};
|
|
3882
3964
|
}
|
|
3883
3965
|
return reader;
|
|
@@ -3890,9 +3972,9 @@
|
|
|
3890
3972
|
if (writer.writable === UNDEFINED_VALUE && typeof writer.next == FUNCTION_TYPE) {
|
|
3891
3973
|
writer = new SplitDataWriter(writer);
|
|
3892
3974
|
}
|
|
3893
|
-
if (writer instanceof WritableStream) {
|
|
3975
|
+
if (writer instanceof WritableStream || typeof writer.getWriter == FUNCTION_TYPE) {
|
|
3894
3976
|
writer = {
|
|
3895
|
-
writable: writer
|
|
3977
|
+
writable: toCompatibleWritable(writer)
|
|
3896
3978
|
};
|
|
3897
3979
|
}
|
|
3898
3980
|
if (writer.size === UNDEFINED_VALUE) {
|
|
@@ -4639,6 +4721,7 @@
|
|
|
4639
4721
|
compressionMethod,
|
|
4640
4722
|
config,
|
|
4641
4723
|
bitFlag,
|
|
4724
|
+
rawBitFlag,
|
|
4642
4725
|
signature,
|
|
4643
4726
|
rawLastModDate,
|
|
4644
4727
|
uncompressedSize,
|
|
@@ -4661,10 +4744,6 @@
|
|
|
4661
4744
|
throw new Error(ERR_UNSUPPORTED_COMPRESSION$1);
|
|
4662
4745
|
}
|
|
4663
4746
|
}
|
|
4664
|
-
const registeredCodec = passThrough ? UNDEFINED_VALUE : getRegisteredCodec(compressionMethod);
|
|
4665
|
-
if ((compressionMethod != COMPRESSION_METHOD_STORE && compressionMethod != COMPRESSION_METHOD_DEFLATE && compressionMethod != COMPRESSION_METHOD_DEFLATE_64 && !registeredCodec) && !passThrough) {
|
|
4666
|
-
throw new Error(ERR_UNSUPPORTED_COMPRESSION$1);
|
|
4667
|
-
}
|
|
4668
4747
|
if (dataArray.length < HEADER_SIZE || getUint32(dataView, 0) != LOCAL_FILE_HEADER_SIGNATURE) {
|
|
4669
4748
|
throw new Error(ERR_LOCAL_FILE_HEADER_NOT_FOUND);
|
|
4670
4749
|
}
|
|
@@ -4700,10 +4779,14 @@
|
|
|
4700
4779
|
if (!passThrough) {
|
|
4701
4780
|
fileEntry.zipCrypto = zipCrypto;
|
|
4702
4781
|
}
|
|
4782
|
+
if (encrypted && (localDirectory.rawBitFlag & BITFLAG_STRONG_ENCRYPTION) == BITFLAG_STRONG_ENCRYPTION) {
|
|
4783
|
+
throw new Error(ERR_UNSUPPORTED_ENCRYPTION);
|
|
4784
|
+
}
|
|
4785
|
+
const registeredCodec = passThrough ? UNDEFINED_VALUE : getRegisteredCodec(compressionMethod);
|
|
4786
|
+
if (compressionMethod != COMPRESSION_METHOD_STORE && compressionMethod != COMPRESSION_METHOD_DEFLATE && compressionMethod != COMPRESSION_METHOD_DEFLATE_64 && !registeredCodec && !passThrough) {
|
|
4787
|
+
throw new Error(ERR_UNSUPPORTED_COMPRESSION$1);
|
|
4788
|
+
}
|
|
4703
4789
|
if (encrypted) {
|
|
4704
|
-
if ((localDirectory.rawBitFlag & BITFLAG_STRONG_ENCRYPTION) == BITFLAG_STRONG_ENCRYPTION) {
|
|
4705
|
-
throw new Error(ERR_UNSUPPORTED_ENCRYPTION);
|
|
4706
|
-
}
|
|
4707
4790
|
if (!zipCrypto && (extraFieldAES.strength < 1 || extraFieldAES.strength > 3)) {
|
|
4708
4791
|
throw new Error(ERR_UNSUPPORTED_ENCRYPTION);
|
|
4709
4792
|
} else if (!password && !rawPassword) {
|
|
@@ -4712,7 +4795,7 @@
|
|
|
4712
4795
|
}
|
|
4713
4796
|
const dataOffset = localHeaderOffset + HEADER_SIZE + filenameLength + extraFieldLength;
|
|
4714
4797
|
const size = compressedSize;
|
|
4715
|
-
const readable = reader.createReadable({ offset: dataOffset, size });
|
|
4798
|
+
const readable = toCompatibleReadable(reader.createReadable({ offset: dataOffset, size }));
|
|
4716
4799
|
const signal = getOptionValue$1(zipEntry, options, OPTION_SIGNAL);
|
|
4717
4800
|
const checkPasswordOnly = getOptionValue$1(zipEntry, options, OPTION_CHECK_PASSWORD_ONLY);
|
|
4718
4801
|
let checkOverlappingEntry = getOptionValue$1(zipEntry, options, OPTION_CHECK_OVERLAPPING_ENTRY);
|
|
@@ -4745,6 +4828,8 @@
|
|
|
4745
4828
|
deflate64,
|
|
4746
4829
|
format: registeredCodec ? registeredCodec.format : UNDEFINED_VALUE,
|
|
4747
4830
|
codecURI: registeredCodec ? registeredCodec.codecURI : UNDEFINED_VALUE,
|
|
4831
|
+
compressionMethod,
|
|
4832
|
+
rawBitFlag,
|
|
4748
4833
|
checkPasswordOnly
|
|
4749
4834
|
},
|
|
4750
4835
|
config,
|
|
@@ -6279,7 +6364,7 @@
|
|
|
6279
6364
|
}
|
|
6280
6365
|
const { writable } = writer;
|
|
6281
6366
|
if (reader) {
|
|
6282
|
-
const readable = reader.createReadable ? reader.createReadable() : reader.readable;
|
|
6367
|
+
const readable = toCompatibleReadable(reader.createReadable ? reader.createReadable() : reader.readable);
|
|
6283
6368
|
const size = reader.size;
|
|
6284
6369
|
const workerOptions = {
|
|
6285
6370
|
options: {
|
|
@@ -6297,7 +6382,8 @@
|
|
|
6297
6382
|
useCompressionStream,
|
|
6298
6383
|
transferStreams,
|
|
6299
6384
|
format,
|
|
6300
|
-
codecURI
|
|
6385
|
+
codecURI,
|
|
6386
|
+
compressionMethod
|
|
6301
6387
|
},
|
|
6302
6388
|
config,
|
|
6303
6389
|
streamOptions: { signal, size, onstart, onprogress, onend }
|