@zip.js/zip.js 2.6.31 → 2.6.33
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/dist/zip-fs-full.js +192 -153
- package/dist/zip-fs-full.min.js +1 -1
- package/dist/zip-fs.js +192 -153
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-full.js +192 -153
- 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 +192 -153
- package/dist/zip.min.js +1 -1
- package/index.cjs +192 -153
- package/index.d.ts +3 -5
- package/lib/core/codec-pool-worker.js +7 -3
- package/lib/core/codec-pool.js +4 -3
- package/lib/core/configuration.js +8 -5
- package/lib/core/constants.js +6 -1
- package/lib/core/io.js +86 -50
- package/lib/core/z-worker-core.js +2 -1
- package/lib/core/zip-reader.js +10 -8
- package/lib/core/zip-writer.js +15 -13
- package/package.json +1 -1
- package/rollup-es5.config.dev.js +199 -0
- package/rollup-es5.config.js +243 -0
- package/tests/all/test-readable-stream.js +1 -2
- package/tests/all/test-readable-zip-stream.js +1 -1
package/dist/zip-fs.js
CHANGED
|
@@ -1058,11 +1058,11 @@
|
|
|
1058
1058
|
const KEY_LENGTH = [16, 24, 32];
|
|
1059
1059
|
const SIGNATURE_LENGTH = 10;
|
|
1060
1060
|
const COUNTER_DEFAULT_VALUE = [0, 0, 0, 0];
|
|
1061
|
-
const UNDEFINED_TYPE = "undefined";
|
|
1061
|
+
const UNDEFINED_TYPE$1 = "undefined";
|
|
1062
1062
|
const FUNCTION_TYPE = "function";
|
|
1063
|
-
const CRYPTO_API_SUPPORTED = typeof crypto != UNDEFINED_TYPE;
|
|
1063
|
+
const CRYPTO_API_SUPPORTED = typeof crypto != UNDEFINED_TYPE$1;
|
|
1064
1064
|
const subtle = CRYPTO_API_SUPPORTED && crypto.subtle;
|
|
1065
|
-
const SUBTLE_API_SUPPORTED = CRYPTO_API_SUPPORTED && typeof subtle != UNDEFINED_TYPE;
|
|
1065
|
+
const SUBTLE_API_SUPPORTED = CRYPTO_API_SUPPORTED && typeof subtle != UNDEFINED_TYPE$1;
|
|
1066
1066
|
const IMPORT_KEY_SUPPORTED = CRYPTO_API_SUPPORTED && SUBTLE_API_SUPPORTED && typeof subtle.importKey == FUNCTION_TYPE;
|
|
1067
1067
|
const DERIVE_BITS_SUPPORTED = CRYPTO_API_SUPPORTED && SUBTLE_API_SUPPORTED && typeof subtle.deriveBits == FUNCTION_TYPE;
|
|
1068
1068
|
const codecBytes = codec.bytes;
|
|
@@ -1749,11 +1749,83 @@
|
|
|
1749
1749
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1750
1750
|
*/
|
|
1751
1751
|
|
|
1752
|
-
const
|
|
1752
|
+
const MAX_32_BITS = 0xffffffff;
|
|
1753
|
+
const MAX_16_BITS = 0xffff;
|
|
1754
|
+
const COMPRESSION_METHOD_DEFLATE = 0x08;
|
|
1755
|
+
const COMPRESSION_METHOD_STORE = 0x00;
|
|
1756
|
+
const COMPRESSION_METHOD_AES = 0x63;
|
|
1757
|
+
|
|
1758
|
+
const LOCAL_FILE_HEADER_SIGNATURE = 0x04034b50;
|
|
1759
|
+
const DATA_DESCRIPTOR_RECORD_SIGNATURE = 0x08074b50;
|
|
1760
|
+
const CENTRAL_FILE_HEADER_SIGNATURE = 0x02014b50;
|
|
1761
|
+
const END_OF_CENTRAL_DIR_SIGNATURE = 0x06054b50;
|
|
1762
|
+
const ZIP64_END_OF_CENTRAL_DIR_SIGNATURE = 0x06064b50;
|
|
1763
|
+
const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE = 0x07064b50;
|
|
1764
|
+
const END_OF_CENTRAL_DIR_LENGTH = 22;
|
|
1765
|
+
const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH = 20;
|
|
1766
|
+
const ZIP64_END_OF_CENTRAL_DIR_LENGTH = 56;
|
|
1767
|
+
const ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH = END_OF_CENTRAL_DIR_LENGTH + ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH + ZIP64_END_OF_CENTRAL_DIR_LENGTH;
|
|
1768
|
+
|
|
1769
|
+
const ZIP64_TOTAL_NUMBER_OF_DISKS = 1;
|
|
1770
|
+
|
|
1771
|
+
const EXTRAFIELD_TYPE_ZIP64 = 0x0001;
|
|
1772
|
+
const EXTRAFIELD_TYPE_AES = 0x9901;
|
|
1773
|
+
const EXTRAFIELD_TYPE_NTFS = 0x000a;
|
|
1774
|
+
const EXTRAFIELD_TYPE_NTFS_TAG1 = 0x0001;
|
|
1775
|
+
const EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP = 0x5455;
|
|
1776
|
+
const EXTRAFIELD_TYPE_UNICODE_PATH = 0x7075;
|
|
1777
|
+
const EXTRAFIELD_TYPE_UNICODE_COMMENT = 0x6375;
|
|
1778
|
+
|
|
1779
|
+
const BITFLAG_ENCRYPTED = 0x01;
|
|
1780
|
+
const BITFLAG_LEVEL = 0x06;
|
|
1781
|
+
const BITFLAG_DATA_DESCRIPTOR = 0x0008;
|
|
1782
|
+
const BITFLAG_LANG_ENCODING_FLAG = 0x0800;
|
|
1783
|
+
const FILE_ATTR_MSDOS_DIR_MASK = 0x10;
|
|
1784
|
+
|
|
1785
|
+
const VERSION_DEFLATE = 0x14;
|
|
1786
|
+
const VERSION_ZIP64 = 0x2D;
|
|
1787
|
+
const VERSION_AES = 0x33;
|
|
1788
|
+
|
|
1789
|
+
const DIRECTORY_SIGNATURE = "/";
|
|
1790
|
+
|
|
1791
|
+
const MAX_DATE = new Date(2107, 11, 31);
|
|
1792
|
+
const MIN_DATE = new Date(1980, 0, 1);
|
|
1793
|
+
|
|
1753
1794
|
const UNDEFINED_VALUE = undefined;
|
|
1795
|
+
const UNDEFINED_TYPE = "undefined";
|
|
1796
|
+
|
|
1797
|
+
/*
|
|
1798
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
1799
|
+
|
|
1800
|
+
Redistribution and use in source and binary forms, with or without
|
|
1801
|
+
modification, are permitted provided that the following conditions are met:
|
|
1802
|
+
|
|
1803
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
1804
|
+
this list of conditions and the following disclaimer.
|
|
1805
|
+
|
|
1806
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
1807
|
+
notice, this list of conditions and the following disclaimer in
|
|
1808
|
+
the documentation and/or other materials provided with the distribution.
|
|
1809
|
+
|
|
1810
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
1811
|
+
derived from this software without specific prior written permission.
|
|
1812
|
+
|
|
1813
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
1814
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
1815
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
1816
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
1817
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
1818
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
1819
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
1820
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
1821
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
1822
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1823
|
+
*/
|
|
1824
|
+
|
|
1825
|
+
const MINIMUM_CHUNK_SIZE = 64;
|
|
1754
1826
|
let maxWorkers = 2;
|
|
1755
1827
|
try {
|
|
1756
|
-
if (typeof navigator !=
|
|
1828
|
+
if (typeof navigator != UNDEFINED_TYPE && navigator.hardwareConcurrency) {
|
|
1757
1829
|
maxWorkers = navigator.hardwareConcurrency;
|
|
1758
1830
|
}
|
|
1759
1831
|
} catch (_error) {
|
|
@@ -1765,9 +1837,9 @@
|
|
|
1765
1837
|
terminateWorkerTimeout: 5000,
|
|
1766
1838
|
useWebWorkers: true,
|
|
1767
1839
|
useCompressionStream: true,
|
|
1768
|
-
workerScripts:
|
|
1769
|
-
CompressionStreamNative: typeof CompressionStream !=
|
|
1770
|
-
DecompressionStreamNative: typeof DecompressionStream !=
|
|
1840
|
+
workerScripts: UNDEFINED_VALUE,
|
|
1841
|
+
CompressionStreamNative: typeof CompressionStream != UNDEFINED_TYPE && CompressionStream,
|
|
1842
|
+
DecompressionStreamNative: typeof DecompressionStream != UNDEFINED_TYPE && DecompressionStream
|
|
1771
1843
|
};
|
|
1772
1844
|
|
|
1773
1845
|
const config = Object.assign({}, DEFAULT_CONFIGURATION);
|
|
@@ -1994,8 +2066,8 @@
|
|
|
1994
2066
|
}
|
|
1995
2067
|
};
|
|
1996
2068
|
workerData.readable = readable.pipeThrough(new TransformStream(transformer, { highWaterMark: 1, size: () => config.chunkSize }), { signal });
|
|
1997
|
-
if (workersSupported ===
|
|
1998
|
-
workersSupported = typeof Worker !=
|
|
2069
|
+
if (workersSupported === UNDEFINED_VALUE) {
|
|
2070
|
+
workersSupported = typeof Worker != UNDEFINED_TYPE;
|
|
1999
2071
|
}
|
|
2000
2072
|
return useWebWorkers && workersSupported ? createWebWorkerInterface(workerData, config) : createWorkerInterface(workerData, config);
|
|
2001
2073
|
}
|
|
@@ -2054,7 +2126,7 @@
|
|
|
2054
2126
|
const writable = new WritableStream({
|
|
2055
2127
|
async write(chunk) {
|
|
2056
2128
|
await writer.ready;
|
|
2057
|
-
await writer.write(
|
|
2129
|
+
await writer.write(chunk);
|
|
2058
2130
|
},
|
|
2059
2131
|
async close() {
|
|
2060
2132
|
writer.releaseLock();
|
|
@@ -2230,11 +2302,11 @@
|
|
|
2230
2302
|
const { options, config } = workerOptions;
|
|
2231
2303
|
const { transferStreams, useWebWorkers, useCompressionStream, codecType, compressed, signed, encrypted } = options;
|
|
2232
2304
|
const { workerScripts } = config;
|
|
2233
|
-
workerOptions.transferStreams = transferStreams || transferStreams ===
|
|
2305
|
+
workerOptions.transferStreams = transferStreams || transferStreams === UNDEFINED_VALUE;
|
|
2234
2306
|
const streamCopy = !compressed && !signed && !encrypted && !workerOptions.transferStreams;
|
|
2235
|
-
workerOptions.useWebWorkers = !streamCopy && (useWebWorkers || (useWebWorkers ===
|
|
2307
|
+
workerOptions.useWebWorkers = !streamCopy && (useWebWorkers || (useWebWorkers === UNDEFINED_VALUE && config.useWebWorkers));
|
|
2236
2308
|
workerOptions.scripts = workerOptions.useWebWorkers && workerScripts ? workerScripts[codecType] : [];
|
|
2237
|
-
options.useCompressionStream = useCompressionStream || (useCompressionStream ===
|
|
2309
|
+
options.useCompressionStream = useCompressionStream || (useCompressionStream === UNDEFINED_VALUE && config.useCompressionStream);
|
|
2238
2310
|
let worker;
|
|
2239
2311
|
if (pool.length < config.maxWorkers) {
|
|
2240
2312
|
const workerData = { indexWorker };
|
|
@@ -2324,11 +2396,14 @@
|
|
|
2324
2396
|
const HTTP_HEADER_CONTENT_RANGE = "Content-Range";
|
|
2325
2397
|
const HTTP_HEADER_ACCEPT_RANGES = "Accept-Ranges";
|
|
2326
2398
|
const HTTP_HEADER_RANGE = "Range";
|
|
2399
|
+
const HTTP_HEADER_CONTENT_TYPE = "Content-Type";
|
|
2327
2400
|
const HTTP_METHOD_HEAD = "HEAD";
|
|
2328
2401
|
const HTTP_METHOD_GET = "GET";
|
|
2329
2402
|
const HTTP_RANGE_UNIT = "bytes";
|
|
2330
2403
|
const DEFAULT_CHUNK_SIZE = 64 * 1024;
|
|
2331
2404
|
|
|
2405
|
+
const PROPERTY_NAME_WRITABLE = "writable";
|
|
2406
|
+
|
|
2332
2407
|
class Stream {
|
|
2333
2408
|
|
|
2334
2409
|
constructor() {
|
|
@@ -2374,7 +2449,7 @@
|
|
|
2374
2449
|
return writer.writeUint8Array(chunk);
|
|
2375
2450
|
}
|
|
2376
2451
|
});
|
|
2377
|
-
Object.defineProperty(writer,
|
|
2452
|
+
Object.defineProperty(writer, PROPERTY_NAME_WRITABLE, {
|
|
2378
2453
|
get() {
|
|
2379
2454
|
return writable;
|
|
2380
2455
|
}
|
|
@@ -2390,21 +2465,26 @@
|
|
|
2390
2465
|
|
|
2391
2466
|
constructor(dataURI) {
|
|
2392
2467
|
super();
|
|
2393
|
-
const reader = this;
|
|
2394
|
-
reader.dataURI = dataURI;
|
|
2395
2468
|
let dataEnd = dataURI.length;
|
|
2396
2469
|
while (dataURI.charAt(dataEnd - 1) == "=") {
|
|
2397
2470
|
dataEnd--;
|
|
2398
2471
|
}
|
|
2399
|
-
|
|
2400
|
-
|
|
2472
|
+
const dataStart = dataURI.indexOf(",") + 1;
|
|
2473
|
+
Object.assign(this, {
|
|
2474
|
+
dataURI,
|
|
2475
|
+
dataStart,
|
|
2476
|
+
size: Math.floor((dataEnd - dataStart) * 0.75)
|
|
2477
|
+
});
|
|
2401
2478
|
}
|
|
2402
2479
|
|
|
2403
2480
|
readUint8Array(offset, length) {
|
|
2481
|
+
const {
|
|
2482
|
+
dataStart,
|
|
2483
|
+
dataURI
|
|
2484
|
+
} = this;
|
|
2404
2485
|
const dataArray = new Uint8Array(length);
|
|
2405
2486
|
const start = Math.floor(offset / 3) * 4;
|
|
2406
|
-
const
|
|
2407
|
-
const bytes = atob(this.dataURI.substring(start + dataStart, Math.ceil((offset + length) / 3) * 4 + dataStart));
|
|
2487
|
+
const bytes = atob(dataURI.substring(start + dataStart, Math.ceil((offset + length) / 3) * 4 + dataStart));
|
|
2408
2488
|
const delta = offset - Math.floor(start / 4) * 3;
|
|
2409
2489
|
for (let indexByte = delta; indexByte < delta + length; indexByte++) {
|
|
2410
2490
|
dataArray[indexByte - delta] = bytes.charCodeAt(indexByte);
|
|
@@ -2417,8 +2497,10 @@
|
|
|
2417
2497
|
|
|
2418
2498
|
constructor(contentType) {
|
|
2419
2499
|
super();
|
|
2420
|
-
|
|
2421
|
-
|
|
2500
|
+
Object.assign(this, {
|
|
2501
|
+
data: "data:" + (contentType || "") + ";base64,",
|
|
2502
|
+
pending: []
|
|
2503
|
+
});
|
|
2422
2504
|
}
|
|
2423
2505
|
|
|
2424
2506
|
writeUint8Array(array) {
|
|
@@ -2449,8 +2531,10 @@
|
|
|
2449
2531
|
|
|
2450
2532
|
constructor(blob) {
|
|
2451
2533
|
super();
|
|
2452
|
-
this
|
|
2453
|
-
|
|
2534
|
+
Object.assign(this, {
|
|
2535
|
+
blob,
|
|
2536
|
+
size: blob.size
|
|
2537
|
+
});
|
|
2454
2538
|
}
|
|
2455
2539
|
|
|
2456
2540
|
async readUint8Array(offset, length) {
|
|
@@ -2467,9 +2551,9 @@
|
|
|
2467
2551
|
const transformStream = new TransformStream();
|
|
2468
2552
|
const headers = [];
|
|
2469
2553
|
if (contentType) {
|
|
2470
|
-
headers.push([
|
|
2554
|
+
headers.push([HTTP_HEADER_CONTENT_TYPE, contentType]);
|
|
2471
2555
|
}
|
|
2472
|
-
Object.defineProperty(writer,
|
|
2556
|
+
Object.defineProperty(writer, PROPERTY_NAME_WRITABLE, {
|
|
2473
2557
|
get() {
|
|
2474
2558
|
return transformStream.writable;
|
|
2475
2559
|
}
|
|
@@ -2510,8 +2594,10 @@
|
|
|
2510
2594
|
} else {
|
|
2511
2595
|
const reader = new FileReader();
|
|
2512
2596
|
return new Promise((resolve, reject) => {
|
|
2513
|
-
reader
|
|
2514
|
-
|
|
2597
|
+
Object.assign(reader, {
|
|
2598
|
+
onload: ({ target }) => resolve(target.result),
|
|
2599
|
+
onerror: () => reject(reader.error)
|
|
2600
|
+
});
|
|
2515
2601
|
reader.readAsText(blob, encoding);
|
|
2516
2602
|
});
|
|
2517
2603
|
}
|
|
@@ -2522,16 +2608,7 @@
|
|
|
2522
2608
|
|
|
2523
2609
|
constructor(url, options) {
|
|
2524
2610
|
super();
|
|
2525
|
-
|
|
2526
|
-
reader.url = url;
|
|
2527
|
-
reader.preventHeadRequest = options.preventHeadRequest;
|
|
2528
|
-
reader.useRangeHeader = options.useRangeHeader;
|
|
2529
|
-
reader.forceRangeRequests = options.forceRangeRequests;
|
|
2530
|
-
reader.options = options = Object.assign({}, options);
|
|
2531
|
-
delete options.preventHeadRequest;
|
|
2532
|
-
delete options.useRangeHeader;
|
|
2533
|
-
delete options.forceRangeRequests;
|
|
2534
|
-
delete options.useXHR;
|
|
2611
|
+
createHtpReader(this, url, options);
|
|
2535
2612
|
}
|
|
2536
2613
|
|
|
2537
2614
|
async init() {
|
|
@@ -2548,12 +2625,7 @@
|
|
|
2548
2625
|
|
|
2549
2626
|
constructor(url, options) {
|
|
2550
2627
|
super();
|
|
2551
|
-
|
|
2552
|
-
reader.url = url;
|
|
2553
|
-
reader.preventHeadRequest = options.preventHeadRequest;
|
|
2554
|
-
reader.useRangeHeader = options.useRangeHeader;
|
|
2555
|
-
reader.forceRangeRequests = options.forceRangeRequests;
|
|
2556
|
-
reader.options = options;
|
|
2628
|
+
createHtpReader(this, url, options);
|
|
2557
2629
|
}
|
|
2558
2630
|
|
|
2559
2631
|
async init() {
|
|
@@ -2566,14 +2638,39 @@
|
|
|
2566
2638
|
}
|
|
2567
2639
|
}
|
|
2568
2640
|
|
|
2641
|
+
function createHtpReader(httpReader, url, options) {
|
|
2642
|
+
const {
|
|
2643
|
+
preventHeadRequest,
|
|
2644
|
+
useRangeHeader,
|
|
2645
|
+
forceRangeRequests
|
|
2646
|
+
} = options;
|
|
2647
|
+
options = Object.assign({}, options);
|
|
2648
|
+
delete options.preventHeadRequest;
|
|
2649
|
+
delete options.useRangeHeader;
|
|
2650
|
+
delete options.forceRangeRequests;
|
|
2651
|
+
delete options.useXHR;
|
|
2652
|
+
Object.assign(httpReader, {
|
|
2653
|
+
url,
|
|
2654
|
+
options,
|
|
2655
|
+
preventHeadRequest,
|
|
2656
|
+
useRangeHeader,
|
|
2657
|
+
forceRangeRequests
|
|
2658
|
+
});
|
|
2659
|
+
}
|
|
2660
|
+
|
|
2569
2661
|
async function initHttpReader(httpReader, sendRequest, getRequestData) {
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2662
|
+
const {
|
|
2663
|
+
url,
|
|
2664
|
+
useRangeHeader,
|
|
2665
|
+
forceRangeRequests
|
|
2666
|
+
} = httpReader;
|
|
2667
|
+
if (isHttpFamily(url) && (useRangeHeader || forceRangeRequests)) {
|
|
2668
|
+
const { headers } = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader));
|
|
2669
|
+
if (!forceRangeRequests && headers.get(HTTP_HEADER_ACCEPT_RANGES) != HTTP_RANGE_UNIT) {
|
|
2573
2670
|
throw new Error(ERR_HTTP_RANGE);
|
|
2574
2671
|
} else {
|
|
2575
2672
|
let contentSize;
|
|
2576
|
-
const contentRangeHeader =
|
|
2673
|
+
const contentRangeHeader = headers.get(HTTP_HEADER_CONTENT_RANGE);
|
|
2577
2674
|
if (contentRangeHeader) {
|
|
2578
2675
|
const splitHeader = contentRangeHeader.trim().split(/\s*\/\s*/);
|
|
2579
2676
|
if (splitHeader.length) {
|
|
@@ -2583,7 +2680,7 @@
|
|
|
2583
2680
|
}
|
|
2584
2681
|
}
|
|
2585
2682
|
}
|
|
2586
|
-
if (contentSize ===
|
|
2683
|
+
if (contentSize === UNDEFINED_VALUE) {
|
|
2587
2684
|
await getContentLength(httpReader, sendRequest, getRequestData);
|
|
2588
2685
|
} else {
|
|
2589
2686
|
httpReader.size = contentSize;
|
|
@@ -2595,17 +2692,23 @@
|
|
|
2595
2692
|
}
|
|
2596
2693
|
|
|
2597
2694
|
async function readUint8ArrayHttpReader(httpReader, index, length, sendRequest, getRequestData) {
|
|
2598
|
-
|
|
2695
|
+
const {
|
|
2696
|
+
data,
|
|
2697
|
+
useRangeHeader,
|
|
2698
|
+
forceRangeRequests,
|
|
2699
|
+
options
|
|
2700
|
+
} = httpReader;
|
|
2701
|
+
if (useRangeHeader || forceRangeRequests) {
|
|
2599
2702
|
const response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader, index, length));
|
|
2600
2703
|
if (response.status != 206) {
|
|
2601
2704
|
throw new Error(ERR_HTTP_RANGE);
|
|
2602
2705
|
}
|
|
2603
2706
|
return new Uint8Array(await response.arrayBuffer());
|
|
2604
2707
|
} else {
|
|
2605
|
-
if (!
|
|
2606
|
-
await getRequestData(httpReader,
|
|
2708
|
+
if (!data) {
|
|
2709
|
+
await getRequestData(httpReader, options);
|
|
2607
2710
|
}
|
|
2608
|
-
return new Uint8Array(
|
|
2711
|
+
return new Uint8Array(data.subarray(index, index + length));
|
|
2609
2712
|
}
|
|
2610
2713
|
}
|
|
2611
2714
|
|
|
@@ -2613,8 +2716,8 @@
|
|
|
2613
2716
|
return Object.assign({}, getHeaders(httpReader), { [HTTP_HEADER_RANGE]: HTTP_RANGE_UNIT + "=" + index + "-" + (index + length - 1) });
|
|
2614
2717
|
}
|
|
2615
2718
|
|
|
2616
|
-
function getHeaders(
|
|
2617
|
-
const headers =
|
|
2719
|
+
function getHeaders({ options }) {
|
|
2720
|
+
const { headers } = options;
|
|
2618
2721
|
if (headers) {
|
|
2619
2722
|
if (Symbol.iterator in headers) {
|
|
2620
2723
|
return Object.fromEntries(headers);
|
|
@@ -2699,9 +2802,10 @@
|
|
|
2699
2802
|
|
|
2700
2803
|
constructor(url, options = {}) {
|
|
2701
2804
|
super();
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2805
|
+
Object.assign(this, {
|
|
2806
|
+
url,
|
|
2807
|
+
reader: options.useXHR ? new XHRReader(url, options) : new FetchReader(url, options)
|
|
2808
|
+
});
|
|
2705
2809
|
}
|
|
2706
2810
|
|
|
2707
2811
|
set size(value) {
|
|
@@ -2735,8 +2839,10 @@
|
|
|
2735
2839
|
|
|
2736
2840
|
constructor(array) {
|
|
2737
2841
|
super();
|
|
2738
|
-
this
|
|
2739
|
-
|
|
2842
|
+
Object.assign(this, {
|
|
2843
|
+
array,
|
|
2844
|
+
size: array.length
|
|
2845
|
+
});
|
|
2740
2846
|
}
|
|
2741
2847
|
|
|
2742
2848
|
readUint8Array(index, length) {
|
|
@@ -2748,9 +2854,10 @@
|
|
|
2748
2854
|
|
|
2749
2855
|
init(initSize = 0) {
|
|
2750
2856
|
super.init();
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2857
|
+
Object.assign(this, {
|
|
2858
|
+
offset: 0,
|
|
2859
|
+
array: new Uint8Array(initSize)
|
|
2860
|
+
});
|
|
2754
2861
|
}
|
|
2755
2862
|
|
|
2756
2863
|
writeUint8Array(array) {
|
|
@@ -2831,76 +2938,6 @@
|
|
|
2831
2938
|
return reader.readUint8Array(offset, size, diskNumber);
|
|
2832
2939
|
}
|
|
2833
2940
|
|
|
2834
|
-
/*
|
|
2835
|
-
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
2836
|
-
|
|
2837
|
-
Redistribution and use in source and binary forms, with or without
|
|
2838
|
-
modification, are permitted provided that the following conditions are met:
|
|
2839
|
-
|
|
2840
|
-
1. Redistributions of source code must retain the above copyright notice,
|
|
2841
|
-
this list of conditions and the following disclaimer.
|
|
2842
|
-
|
|
2843
|
-
2. Redistributions in binary form must reproduce the above copyright
|
|
2844
|
-
notice, this list of conditions and the following disclaimer in
|
|
2845
|
-
the documentation and/or other materials provided with the distribution.
|
|
2846
|
-
|
|
2847
|
-
3. The names of the authors may not be used to endorse or promote products
|
|
2848
|
-
derived from this software without specific prior written permission.
|
|
2849
|
-
|
|
2850
|
-
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
2851
|
-
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
2852
|
-
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
2853
|
-
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
2854
|
-
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
2855
|
-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
2856
|
-
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
2857
|
-
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
2858
|
-
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
2859
|
-
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
2860
|
-
*/
|
|
2861
|
-
|
|
2862
|
-
const MAX_32_BITS = 0xffffffff;
|
|
2863
|
-
const MAX_16_BITS = 0xffff;
|
|
2864
|
-
const COMPRESSION_METHOD_DEFLATE = 0x08;
|
|
2865
|
-
const COMPRESSION_METHOD_STORE = 0x00;
|
|
2866
|
-
const COMPRESSION_METHOD_AES = 0x63;
|
|
2867
|
-
|
|
2868
|
-
const LOCAL_FILE_HEADER_SIGNATURE = 0x04034b50;
|
|
2869
|
-
const DATA_DESCRIPTOR_RECORD_SIGNATURE = 0x08074b50;
|
|
2870
|
-
const CENTRAL_FILE_HEADER_SIGNATURE = 0x02014b50;
|
|
2871
|
-
const END_OF_CENTRAL_DIR_SIGNATURE = 0x06054b50;
|
|
2872
|
-
const ZIP64_END_OF_CENTRAL_DIR_SIGNATURE = 0x06064b50;
|
|
2873
|
-
const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE = 0x07064b50;
|
|
2874
|
-
const END_OF_CENTRAL_DIR_LENGTH = 22;
|
|
2875
|
-
const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH = 20;
|
|
2876
|
-
const ZIP64_END_OF_CENTRAL_DIR_LENGTH = 56;
|
|
2877
|
-
const ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH = END_OF_CENTRAL_DIR_LENGTH + ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH + ZIP64_END_OF_CENTRAL_DIR_LENGTH;
|
|
2878
|
-
|
|
2879
|
-
const ZIP64_TOTAL_NUMBER_OF_DISKS = 1;
|
|
2880
|
-
|
|
2881
|
-
const EXTRAFIELD_TYPE_ZIP64 = 0x0001;
|
|
2882
|
-
const EXTRAFIELD_TYPE_AES = 0x9901;
|
|
2883
|
-
const EXTRAFIELD_TYPE_NTFS = 0x000a;
|
|
2884
|
-
const EXTRAFIELD_TYPE_NTFS_TAG1 = 0x0001;
|
|
2885
|
-
const EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP = 0x5455;
|
|
2886
|
-
const EXTRAFIELD_TYPE_UNICODE_PATH = 0x7075;
|
|
2887
|
-
const EXTRAFIELD_TYPE_UNICODE_COMMENT = 0x6375;
|
|
2888
|
-
|
|
2889
|
-
const BITFLAG_ENCRYPTED = 0x01;
|
|
2890
|
-
const BITFLAG_LEVEL = 0x06;
|
|
2891
|
-
const BITFLAG_DATA_DESCRIPTOR = 0x0008;
|
|
2892
|
-
const BITFLAG_LANG_ENCODING_FLAG = 0x0800;
|
|
2893
|
-
const FILE_ATTR_MSDOS_DIR_MASK = 0x10;
|
|
2894
|
-
|
|
2895
|
-
const VERSION_DEFLATE = 0x14;
|
|
2896
|
-
const VERSION_ZIP64 = 0x2D;
|
|
2897
|
-
const VERSION_AES = 0x33;
|
|
2898
|
-
|
|
2899
|
-
const DIRECTORY_SIGNATURE = "/";
|
|
2900
|
-
|
|
2901
|
-
const MAX_DATE = new Date(2107, 11, 31);
|
|
2902
|
-
const MIN_DATE = new Date(1980, 0, 1);
|
|
2903
|
-
|
|
2904
2941
|
/*
|
|
2905
2942
|
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
2906
2943
|
|
|
@@ -3105,7 +3142,7 @@
|
|
|
3105
3142
|
let { reader } = zipReader;
|
|
3106
3143
|
const { config } = zipReader;
|
|
3107
3144
|
await initStream(reader);
|
|
3108
|
-
if (reader.size ===
|
|
3145
|
+
if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
|
|
3109
3146
|
if (Array.isArray(reader)) {
|
|
3110
3147
|
reader = new SplitZipReader(reader);
|
|
3111
3148
|
} else {
|
|
@@ -3135,7 +3172,7 @@
|
|
|
3135
3172
|
const commentLength = getUint16(endOfDirectoryView, 20);
|
|
3136
3173
|
const appendedDataOffset = commentOffset + END_OF_CENTRAL_DIR_LENGTH + commentLength;
|
|
3137
3174
|
let diskNumber = getUint16(endOfDirectoryView, 4);
|
|
3138
|
-
if (lastDiskNumber !==
|
|
3175
|
+
if (lastDiskNumber !== UNDEFINED_VALUE && diskNumber != lastDiskNumber) {
|
|
3139
3176
|
throw new Error(ERR_SPLIT_ZIP_FILE);
|
|
3140
3177
|
}
|
|
3141
3178
|
let filesLength = getUint16(endOfDirectoryView, 8);
|
|
@@ -3320,8 +3357,9 @@
|
|
|
3320
3357
|
throw new Error(ERR_LOCAL_FILE_HEADER_NOT_FOUND);
|
|
3321
3358
|
}
|
|
3322
3359
|
readCommonHeader(localDirectory, dataView, 4);
|
|
3323
|
-
|
|
3324
|
-
|
|
3360
|
+
localDirectory.rawExtraField = localDirectory.extraFieldLength ?
|
|
3361
|
+
await readUint8Array(reader, offset + 30 + localDirectory.filenameLength, localDirectory.extraFieldLength, diskNumberStart) :
|
|
3362
|
+
new Uint8Array();
|
|
3325
3363
|
await readCommonFooter(zipEntry, localDirectory, dataView, 4);
|
|
3326
3364
|
Object.assign(fileEntry, {
|
|
3327
3365
|
lastAccessDate: localDirectory.lastAccessDate,
|
|
@@ -3330,7 +3368,7 @@
|
|
|
3330
3368
|
const encrypted = zipEntry.encrypted && localDirectory.encrypted;
|
|
3331
3369
|
const zipCrypto = encrypted && !extraFieldAES;
|
|
3332
3370
|
if (encrypted) {
|
|
3333
|
-
if (!zipCrypto && extraFieldAES.strength ===
|
|
3371
|
+
if (!zipCrypto && extraFieldAES.strength === UNDEFINED_VALUE) {
|
|
3334
3372
|
throw new Error(ERR_UNSUPPORTED_ENCRYPTION);
|
|
3335
3373
|
} else if (!password) {
|
|
3336
3374
|
throw new Error(ERR_ENCRYPTED);
|
|
@@ -3347,7 +3385,7 @@
|
|
|
3347
3385
|
};
|
|
3348
3386
|
}
|
|
3349
3387
|
const { writable } = writer;
|
|
3350
|
-
if (writable.size ===
|
|
3388
|
+
if (writable.size === UNDEFINED_VALUE) {
|
|
3351
3389
|
writable.size = 0;
|
|
3352
3390
|
}
|
|
3353
3391
|
const signal = getOptionValue$1(zipEntry, options, "signal");
|
|
@@ -3595,7 +3633,7 @@
|
|
|
3595
3633
|
}
|
|
3596
3634
|
|
|
3597
3635
|
function getOptionValue$1(zipReader, options, name) {
|
|
3598
|
-
return options[name] ===
|
|
3636
|
+
return options[name] === UNDEFINED_VALUE ? zipReader.options[name] : options[name];
|
|
3599
3637
|
}
|
|
3600
3638
|
|
|
3601
3639
|
function getDate(timeRaw) {
|
|
@@ -3685,7 +3723,7 @@
|
|
|
3685
3723
|
if (writer instanceof WritableStream) {
|
|
3686
3724
|
writer = { writable: writer };
|
|
3687
3725
|
}
|
|
3688
|
-
if (writer.writable.size ===
|
|
3726
|
+
if (writer.writable.size === UNDEFINED_VALUE) {
|
|
3689
3727
|
writer.writable.size = 0;
|
|
3690
3728
|
}
|
|
3691
3729
|
Object.assign(this, {
|
|
@@ -3779,7 +3817,7 @@
|
|
|
3779
3817
|
const password = getOptionValue(zipWriter, options, "password");
|
|
3780
3818
|
const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength") || 3;
|
|
3781
3819
|
const zipCrypto = getOptionValue(zipWriter, options, "zipCrypto");
|
|
3782
|
-
if (password !==
|
|
3820
|
+
if (password !== UNDEFINED_VALUE && encryptionStrength !== UNDEFINED_VALUE && (encryptionStrength < 1 || encryptionStrength > 3)) {
|
|
3783
3821
|
throw new Error(ERR_INVALID_ENCRYPTION_STRENGTH);
|
|
3784
3822
|
}
|
|
3785
3823
|
let rawExtraField = new Uint8Array();
|
|
@@ -3803,18 +3841,18 @@
|
|
|
3803
3841
|
});
|
|
3804
3842
|
}
|
|
3805
3843
|
let extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp");
|
|
3806
|
-
if (extendedTimestamp ===
|
|
3844
|
+
if (extendedTimestamp === UNDEFINED_VALUE) {
|
|
3807
3845
|
extendedTimestamp = true;
|
|
3808
3846
|
}
|
|
3809
3847
|
let maximumCompressedSize = 0;
|
|
3810
3848
|
let maximumEntrySize = 0;
|
|
3811
3849
|
let keepOrder = getOptionValue(zipWriter, options, "keepOrder");
|
|
3812
|
-
if (keepOrder ===
|
|
3850
|
+
if (keepOrder === UNDEFINED_VALUE) {
|
|
3813
3851
|
keepOrder = true;
|
|
3814
3852
|
}
|
|
3815
3853
|
let uncompressedSize = 0;
|
|
3816
3854
|
let msDosCompatible = getOptionValue(zipWriter, options, "msDosCompatible");
|
|
3817
|
-
if (msDosCompatible ===
|
|
3855
|
+
if (msDosCompatible === UNDEFINED_VALUE) {
|
|
3818
3856
|
msDosCompatible = true;
|
|
3819
3857
|
}
|
|
3820
3858
|
const internalFileAttribute = getOptionValue(zipWriter, options, "internalFileAttribute") || 0;
|
|
@@ -3827,15 +3865,16 @@
|
|
|
3827
3865
|
};
|
|
3828
3866
|
}
|
|
3829
3867
|
await initStream(reader);
|
|
3830
|
-
if (reader.size ===
|
|
3868
|
+
if (reader.size === UNDEFINED_VALUE) {
|
|
3831
3869
|
options.dataDescriptor = true;
|
|
3832
|
-
if (zip64 ===
|
|
3870
|
+
if (zip64 || zip64 === UNDEFINED_VALUE) {
|
|
3833
3871
|
zip64 = true;
|
|
3872
|
+
maximumCompressedSize = MAX_32_BITS;
|
|
3834
3873
|
}
|
|
3835
3874
|
} else {
|
|
3836
3875
|
uncompressedSize = reader.size;
|
|
3876
|
+
maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
|
|
3837
3877
|
}
|
|
3838
|
-
maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
|
|
3839
3878
|
}
|
|
3840
3879
|
if (zipWriter.offset + zipWriter.pendingEntriesSize >= MAX_32_BITS ||
|
|
3841
3880
|
uncompressedSize >= MAX_32_BITS ||
|
|
@@ -3854,10 +3893,10 @@
|
|
|
3854
3893
|
let dataDescriptorSignature = getOptionValue(zipWriter, options, "dataDescriptorSignature");
|
|
3855
3894
|
const signal = getOptionValue(zipWriter, options, "signal");
|
|
3856
3895
|
const useCompressionStream = getOptionValue(zipWriter, options, "useCompressionStream");
|
|
3857
|
-
if (dataDescriptor ===
|
|
3896
|
+
if (dataDescriptor === UNDEFINED_VALUE) {
|
|
3858
3897
|
dataDescriptor = true;
|
|
3859
3898
|
}
|
|
3860
|
-
if (dataDescriptor && dataDescriptorSignature ===
|
|
3899
|
+
if (dataDescriptor && dataDescriptorSignature === UNDEFINED_VALUE) {
|
|
3861
3900
|
dataDescriptorSignature = false;
|
|
3862
3901
|
}
|
|
3863
3902
|
options = Object.assign({}, options, {
|
|
@@ -4324,7 +4363,7 @@
|
|
|
4324
4363
|
zipCrypto,
|
|
4325
4364
|
dataDescriptor
|
|
4326
4365
|
} = options;
|
|
4327
|
-
if ((!encrypted || zipCrypto) && signature !==
|
|
4366
|
+
if ((!encrypted || zipCrypto) && signature !== UNDEFINED_VALUE) {
|
|
4328
4367
|
setUint32(headerView, 10, signature);
|
|
4329
4368
|
if (dataDescriptor) {
|
|
4330
4369
|
setUint32(dataDescriptorView, dataDescriptorOffset, signature);
|
|
@@ -4511,7 +4550,7 @@
|
|
|
4511
4550
|
}
|
|
4512
4551
|
|
|
4513
4552
|
function getOptionValue(zipWriter, options, name) {
|
|
4514
|
-
return options[name] ===
|
|
4553
|
+
return options[name] === UNDEFINED_VALUE ? zipWriter.options[name] : options[name];
|
|
4515
4554
|
}
|
|
4516
4555
|
|
|
4517
4556
|
function getMaximumCompressedSize(uncompressedSize) {
|