@zip.js/zip.js 2.8.39 → 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/deno.json +1 -1
- package/dist/zip-core.js +113 -27
- package/dist/zip-core.min.js +1 -1
- package/dist/zip-fs-core.js +113 -27
- package/dist/zip-fs-core.min.js +1 -1
- package/dist/zip-fs-native.js +115 -29
- package/dist/zip-fs-native.min.js +1 -1
- package/dist/zip-fs.js +114 -28
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-legacy.js +115 -29
- package/dist/zip-legacy.min.js +1 -1
- package/dist/zip-native.js +115 -29
- 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 +114 -28
- package/dist/zip.min.js +1 -1
- package/index-native.cjs +115 -29
- package/index-native.min.js +1 -1
- package/index.cjs +114 -28
- 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 +27 -11
- 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/dist/zip-fs-core.js
CHANGED
|
@@ -223,6 +223,73 @@
|
|
|
223
223
|
return new DataView(array.buffer, array.byteOffset, array.byteLength);
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
+
/*
|
|
227
|
+
Copyright (c) 2026 Gildas Lormeau. All rights reserved.
|
|
228
|
+
|
|
229
|
+
Redistribution and use in source and binary forms, with or without
|
|
230
|
+
modification, are permitted provided that the following conditions are met:
|
|
231
|
+
|
|
232
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
233
|
+
this list of conditions and the following disclaimer.
|
|
234
|
+
|
|
235
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
236
|
+
notice, this list of conditions and the following disclaimer in
|
|
237
|
+
the documentation and/or other materials provided with the distribution.
|
|
238
|
+
|
|
239
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
240
|
+
derived from this software without specific prior written permission.
|
|
241
|
+
|
|
242
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
243
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
244
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
245
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
246
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
247
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
248
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
249
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
250
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
251
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
252
|
+
*/
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
function toCompatibleReadable(readable) {
|
|
256
|
+
if (readable instanceof ReadableStream) {
|
|
257
|
+
return readable;
|
|
258
|
+
}
|
|
259
|
+
const reader = readable.getReader();
|
|
260
|
+
return new ReadableStream({
|
|
261
|
+
async pull(controller) {
|
|
262
|
+
const { value, done } = await reader.read();
|
|
263
|
+
if (done) {
|
|
264
|
+
controller.close();
|
|
265
|
+
} else {
|
|
266
|
+
controller.enqueue(value);
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
cancel(reason) {
|
|
270
|
+
return reader.cancel(reason);
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function toCompatibleWritable(writable) {
|
|
276
|
+
if (writable instanceof WritableStream) {
|
|
277
|
+
return writable;
|
|
278
|
+
}
|
|
279
|
+
const writer = writable.getWriter();
|
|
280
|
+
return new WritableStream({
|
|
281
|
+
write(chunk) {
|
|
282
|
+
return writer.write(chunk);
|
|
283
|
+
},
|
|
284
|
+
close() {
|
|
285
|
+
return writer.close();
|
|
286
|
+
},
|
|
287
|
+
abort(reason) {
|
|
288
|
+
return writer.abort(reason);
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
|
|
226
293
|
/*
|
|
227
294
|
Copyright (c) 2025 Gildas Lormeau. All rights reserved.
|
|
228
295
|
|
|
@@ -447,10 +514,10 @@
|
|
|
447
514
|
const { blob, size } = reader;
|
|
448
515
|
const { offset = 0, size: readSize = size - offset } = options || {};
|
|
449
516
|
if (!offset && readSize >= size) {
|
|
450
|
-
return blob.stream();
|
|
517
|
+
return toCompatibleReadable(blob.stream());
|
|
451
518
|
}
|
|
452
519
|
if (blobSliceReliable) {
|
|
453
|
-
return blob.slice(offset, offset + readSize).stream();
|
|
520
|
+
return toCompatibleReadable(blob.slice(offset, offset + readSize).stream());
|
|
454
521
|
}
|
|
455
522
|
return super.createReadable(options);
|
|
456
523
|
}
|
|
@@ -469,22 +536,37 @@
|
|
|
469
536
|
}
|
|
470
537
|
}
|
|
471
538
|
|
|
539
|
+
function responseSupportsGlobalReadable() {
|
|
540
|
+
return typeof Blob.prototype.stream != FUNCTION_TYPE || new Blob([]).stream() instanceof ReadableStream;
|
|
541
|
+
}
|
|
542
|
+
|
|
472
543
|
class BlobWriter extends Stream {
|
|
473
544
|
|
|
474
545
|
constructor(contentType) {
|
|
475
546
|
super();
|
|
476
547
|
const writer = this;
|
|
477
548
|
const transformStream = new TransformStream();
|
|
478
|
-
const headers = [];
|
|
479
|
-
if (contentType) {
|
|
480
|
-
headers.push([HTTP_HEADER_CONTENT_TYPE, contentType]);
|
|
481
|
-
}
|
|
482
549
|
Object.defineProperty(writer, PROPERTY_NAME_WRITABLE, {
|
|
483
550
|
get() {
|
|
484
551
|
return transformStream.writable;
|
|
485
552
|
}
|
|
486
553
|
});
|
|
487
|
-
|
|
554
|
+
if (responseSupportsGlobalReadable()) {
|
|
555
|
+
const headers = [];
|
|
556
|
+
if (contentType) {
|
|
557
|
+
headers.push([HTTP_HEADER_CONTENT_TYPE, contentType]);
|
|
558
|
+
}
|
|
559
|
+
writer.blob = new Response(transformStream.readable, { headers }).blob();
|
|
560
|
+
} else {
|
|
561
|
+
const chunks = [];
|
|
562
|
+
writer.blob = transformStream.readable
|
|
563
|
+
.pipeTo(new WritableStream({
|
|
564
|
+
write(chunk) {
|
|
565
|
+
chunks.push(chunk);
|
|
566
|
+
}
|
|
567
|
+
}))
|
|
568
|
+
.then(() => new Blob(chunks, { type: contentType }));
|
|
569
|
+
}
|
|
488
570
|
writer.blob.catch(() => { });
|
|
489
571
|
}
|
|
490
572
|
|
|
@@ -1129,9 +1211,9 @@
|
|
|
1129
1211
|
if (Array.isArray(reader)) {
|
|
1130
1212
|
reader = new SplitDataReader(reader);
|
|
1131
1213
|
}
|
|
1132
|
-
if (reader instanceof ReadableStream) {
|
|
1214
|
+
if (reader instanceof ReadableStream || typeof reader.getReader == FUNCTION_TYPE) {
|
|
1133
1215
|
reader = {
|
|
1134
|
-
readable: reader
|
|
1216
|
+
readable: toCompatibleReadable(reader)
|
|
1135
1217
|
};
|
|
1136
1218
|
}
|
|
1137
1219
|
return reader;
|
|
@@ -1144,9 +1226,9 @@
|
|
|
1144
1226
|
if (writer.writable === UNDEFINED_VALUE && typeof writer.next == FUNCTION_TYPE) {
|
|
1145
1227
|
writer = new SplitDataWriter(writer);
|
|
1146
1228
|
}
|
|
1147
|
-
if (writer instanceof WritableStream) {
|
|
1229
|
+
if (writer instanceof WritableStream || typeof writer.getWriter == FUNCTION_TYPE) {
|
|
1148
1230
|
writer = {
|
|
1149
|
-
writable: writer
|
|
1231
|
+
writable: toCompatibleWritable(writer)
|
|
1150
1232
|
};
|
|
1151
1233
|
}
|
|
1152
1234
|
if (writer.size === UNDEFINED_VALUE) {
|
|
@@ -1225,7 +1307,7 @@
|
|
|
1225
1307
|
|
|
1226
1308
|
async function ensureCodecStreams(format, codecURI) {
|
|
1227
1309
|
if (!codecStreams.has(format) && codecURI) {
|
|
1228
|
-
setCodecStreams(format, await import(codecURI));
|
|
1310
|
+
setCodecStreams(format, await import(/* webpackIgnore: true */ /* @vite-ignore */ codecURI));
|
|
1229
1311
|
}
|
|
1230
1312
|
}
|
|
1231
1313
|
|
|
@@ -2732,7 +2814,7 @@
|
|
|
2732
2814
|
|
|
2733
2815
|
constructor(options, { chunkSize, CompressionStreamZlib, CompressionStream }) {
|
|
2734
2816
|
super({});
|
|
2735
|
-
const { compressed, encrypted, useCompressionStream, zipCrypto, signed, level, deflate64, format } = options;
|
|
2817
|
+
const { compressed, encrypted, useCompressionStream, zipCrypto, signed, level, deflate64, format, compressionMethod } = options;
|
|
2736
2818
|
const stream = this;
|
|
2737
2819
|
let crc32Stream, encryptionStream, gzipCrc32Stream;
|
|
2738
2820
|
let readable = super.readable;
|
|
@@ -2745,7 +2827,7 @@
|
|
|
2745
2827
|
}
|
|
2746
2828
|
if (compressed) {
|
|
2747
2829
|
if (codecStreams) {
|
|
2748
|
-
readable = pipeThroughBackpressured(readable, createCodecStream(codecStreams.CompressionStream, format, { level, chunkSize }));
|
|
2830
|
+
readable = pipeThroughBackpressured(readable, createCodecStream(codecStreams.CompressionStream, format, { level, chunkSize, compressionMethod }));
|
|
2749
2831
|
} else if (useGzipCrc32) {
|
|
2750
2832
|
gzipCrc32Stream = new GzipToRawDeflateStream();
|
|
2751
2833
|
readable = pipeThroughBackpressured(readable, new CompressionStream(FORMAT_GZIP));
|
|
@@ -2820,7 +2902,7 @@
|
|
|
2820
2902
|
|
|
2821
2903
|
constructor(options, { chunkSize, DecompressionStreamZlib, DecompressionStream }) {
|
|
2822
2904
|
super({});
|
|
2823
|
-
const { zipCrypto, encrypted, signed, signature, compressed, useCompressionStream, deflate64, format } = options;
|
|
2905
|
+
const { zipCrypto, encrypted, signed, signature, compressed, useCompressionStream, deflate64, format, compressionMethod, rawBitFlag, outputSize } = options;
|
|
2824
2906
|
let crc32Stream, decryptionStream;
|
|
2825
2907
|
let readable = super.readable;
|
|
2826
2908
|
if (encrypted) {
|
|
@@ -2834,7 +2916,7 @@
|
|
|
2834
2916
|
if (compressed) {
|
|
2835
2917
|
const codecStreams = format && getCodecStreams(format);
|
|
2836
2918
|
if (codecStreams) {
|
|
2837
|
-
readable = pipeThroughBackpressured(readable, createCodecStream(codecStreams.DecompressionStream, format, { chunkSize }));
|
|
2919
|
+
readable = pipeThroughBackpressured(readable, createCodecStream(codecStreams.DecompressionStream, format, { chunkSize, compressionMethod, rawBitFlag, uncompressedSize: outputSize }));
|
|
2838
2920
|
} else {
|
|
2839
2921
|
readable = pipeThroughCompressionStream(readable, useCompressionStream, { chunkSize, deflate64 }, DecompressionStream, DecompressionStreamZlib);
|
|
2840
2922
|
}
|
|
@@ -2909,7 +2991,7 @@
|
|
|
2909
2991
|
}
|
|
2910
2992
|
|
|
2911
2993
|
function pipeThrough(readable, transformStream) {
|
|
2912
|
-
return readable.pipeThrough(transformStream);
|
|
2994
|
+
return toCompatibleReadable(readable).pipeThrough(transformStream);
|
|
2913
2995
|
}
|
|
2914
2996
|
|
|
2915
2997
|
function pipeThroughBackpressured(readable, transformStream) {
|
|
@@ -4493,6 +4575,7 @@
|
|
|
4493
4575
|
compressionMethod,
|
|
4494
4576
|
config,
|
|
4495
4577
|
bitFlag,
|
|
4578
|
+
rawBitFlag,
|
|
4496
4579
|
signature,
|
|
4497
4580
|
rawLastModDate,
|
|
4498
4581
|
uncompressedSize,
|
|
@@ -4515,10 +4598,6 @@
|
|
|
4515
4598
|
throw new Error(ERR_UNSUPPORTED_COMPRESSION$1);
|
|
4516
4599
|
}
|
|
4517
4600
|
}
|
|
4518
|
-
const registeredCodec = passThrough ? UNDEFINED_VALUE : getRegisteredCodec(compressionMethod);
|
|
4519
|
-
if ((compressionMethod != COMPRESSION_METHOD_STORE && compressionMethod != COMPRESSION_METHOD_DEFLATE && compressionMethod != COMPRESSION_METHOD_DEFLATE_64 && !registeredCodec) && !passThrough) {
|
|
4520
|
-
throw new Error(ERR_UNSUPPORTED_COMPRESSION$1);
|
|
4521
|
-
}
|
|
4522
4601
|
if (dataArray.length < HEADER_SIZE || getUint32(dataView, 0) != LOCAL_FILE_HEADER_SIGNATURE) {
|
|
4523
4602
|
throw new Error(ERR_LOCAL_FILE_HEADER_NOT_FOUND);
|
|
4524
4603
|
}
|
|
@@ -4554,10 +4633,14 @@
|
|
|
4554
4633
|
if (!passThrough) {
|
|
4555
4634
|
fileEntry.zipCrypto = zipCrypto;
|
|
4556
4635
|
}
|
|
4636
|
+
if (encrypted && (localDirectory.rawBitFlag & BITFLAG_STRONG_ENCRYPTION) == BITFLAG_STRONG_ENCRYPTION) {
|
|
4637
|
+
throw new Error(ERR_UNSUPPORTED_ENCRYPTION);
|
|
4638
|
+
}
|
|
4639
|
+
const registeredCodec = passThrough ? UNDEFINED_VALUE : getRegisteredCodec(compressionMethod);
|
|
4640
|
+
if (compressionMethod != COMPRESSION_METHOD_STORE && compressionMethod != COMPRESSION_METHOD_DEFLATE && compressionMethod != COMPRESSION_METHOD_DEFLATE_64 && !registeredCodec && !passThrough) {
|
|
4641
|
+
throw new Error(ERR_UNSUPPORTED_COMPRESSION$1);
|
|
4642
|
+
}
|
|
4557
4643
|
if (encrypted) {
|
|
4558
|
-
if ((localDirectory.rawBitFlag & BITFLAG_STRONG_ENCRYPTION) == BITFLAG_STRONG_ENCRYPTION) {
|
|
4559
|
-
throw new Error(ERR_UNSUPPORTED_ENCRYPTION);
|
|
4560
|
-
}
|
|
4561
4644
|
if (!zipCrypto && (extraFieldAES.strength < 1 || extraFieldAES.strength > 3)) {
|
|
4562
4645
|
throw new Error(ERR_UNSUPPORTED_ENCRYPTION);
|
|
4563
4646
|
} else if (!password && !rawPassword) {
|
|
@@ -4566,7 +4649,7 @@
|
|
|
4566
4649
|
}
|
|
4567
4650
|
const dataOffset = localHeaderOffset + HEADER_SIZE + filenameLength + extraFieldLength;
|
|
4568
4651
|
const size = compressedSize;
|
|
4569
|
-
const readable = reader.createReadable({ offset: dataOffset, size });
|
|
4652
|
+
const readable = toCompatibleReadable(reader.createReadable({ offset: dataOffset, size }));
|
|
4570
4653
|
const signal = getOptionValue$1(zipEntry, options, OPTION_SIGNAL);
|
|
4571
4654
|
const checkPasswordOnly = getOptionValue$1(zipEntry, options, OPTION_CHECK_PASSWORD_ONLY);
|
|
4572
4655
|
let checkOverlappingEntry = getOptionValue$1(zipEntry, options, OPTION_CHECK_OVERLAPPING_ENTRY);
|
|
@@ -4599,6 +4682,8 @@
|
|
|
4599
4682
|
deflate64,
|
|
4600
4683
|
format: registeredCodec ? registeredCodec.format : UNDEFINED_VALUE,
|
|
4601
4684
|
codecURI: registeredCodec ? registeredCodec.codecURI : UNDEFINED_VALUE,
|
|
4685
|
+
compressionMethod,
|
|
4686
|
+
rawBitFlag,
|
|
4602
4687
|
checkPasswordOnly
|
|
4603
4688
|
},
|
|
4604
4689
|
config,
|
|
@@ -6070,7 +6155,7 @@
|
|
|
6070
6155
|
}
|
|
6071
6156
|
const { writable } = writer;
|
|
6072
6157
|
if (reader) {
|
|
6073
|
-
const readable = reader.createReadable ? reader.createReadable() : reader.readable;
|
|
6158
|
+
const readable = toCompatibleReadable(reader.createReadable ? reader.createReadable() : reader.readable);
|
|
6074
6159
|
const size = reader.size;
|
|
6075
6160
|
const workerOptions = {
|
|
6076
6161
|
options: {
|
|
@@ -6088,7 +6173,8 @@
|
|
|
6088
6173
|
useCompressionStream,
|
|
6089
6174
|
transferStreams,
|
|
6090
6175
|
format,
|
|
6091
|
-
codecURI
|
|
6176
|
+
codecURI,
|
|
6177
|
+
compressionMethod
|
|
6092
6178
|
},
|
|
6093
6179
|
config,
|
|
6094
6180
|
streamOptions: { signal, size, onstart, onprogress, onend }
|