@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-full.js
CHANGED
|
@@ -5281,11 +5281,11 @@
|
|
|
5281
5281
|
const KEY_LENGTH = [16, 24, 32];
|
|
5282
5282
|
const SIGNATURE_LENGTH = 10;
|
|
5283
5283
|
const COUNTER_DEFAULT_VALUE = [0, 0, 0, 0];
|
|
5284
|
-
const UNDEFINED_TYPE = "undefined";
|
|
5284
|
+
const UNDEFINED_TYPE$1 = "undefined";
|
|
5285
5285
|
const FUNCTION_TYPE = "function";
|
|
5286
|
-
const CRYPTO_API_SUPPORTED = typeof crypto != UNDEFINED_TYPE;
|
|
5286
|
+
const CRYPTO_API_SUPPORTED = typeof crypto != UNDEFINED_TYPE$1;
|
|
5287
5287
|
const subtle = CRYPTO_API_SUPPORTED && crypto.subtle;
|
|
5288
|
-
const SUBTLE_API_SUPPORTED = CRYPTO_API_SUPPORTED && typeof subtle != UNDEFINED_TYPE;
|
|
5288
|
+
const SUBTLE_API_SUPPORTED = CRYPTO_API_SUPPORTED && typeof subtle != UNDEFINED_TYPE$1;
|
|
5289
5289
|
const IMPORT_KEY_SUPPORTED = CRYPTO_API_SUPPORTED && SUBTLE_API_SUPPORTED && typeof subtle.importKey == FUNCTION_TYPE;
|
|
5290
5290
|
const DERIVE_BITS_SUPPORTED = CRYPTO_API_SUPPORTED && SUBTLE_API_SUPPORTED && typeof subtle.deriveBits == FUNCTION_TYPE;
|
|
5291
5291
|
const codecBytes = codec.bytes;
|
|
@@ -5972,11 +5972,83 @@
|
|
|
5972
5972
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
5973
5973
|
*/
|
|
5974
5974
|
|
|
5975
|
-
const
|
|
5975
|
+
const MAX_32_BITS = 0xffffffff;
|
|
5976
|
+
const MAX_16_BITS = 0xffff;
|
|
5977
|
+
const COMPRESSION_METHOD_DEFLATE = 0x08;
|
|
5978
|
+
const COMPRESSION_METHOD_STORE = 0x00;
|
|
5979
|
+
const COMPRESSION_METHOD_AES = 0x63;
|
|
5980
|
+
|
|
5981
|
+
const LOCAL_FILE_HEADER_SIGNATURE = 0x04034b50;
|
|
5982
|
+
const DATA_DESCRIPTOR_RECORD_SIGNATURE = 0x08074b50;
|
|
5983
|
+
const CENTRAL_FILE_HEADER_SIGNATURE = 0x02014b50;
|
|
5984
|
+
const END_OF_CENTRAL_DIR_SIGNATURE = 0x06054b50;
|
|
5985
|
+
const ZIP64_END_OF_CENTRAL_DIR_SIGNATURE = 0x06064b50;
|
|
5986
|
+
const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE = 0x07064b50;
|
|
5987
|
+
const END_OF_CENTRAL_DIR_LENGTH = 22;
|
|
5988
|
+
const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH = 20;
|
|
5989
|
+
const ZIP64_END_OF_CENTRAL_DIR_LENGTH = 56;
|
|
5990
|
+
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;
|
|
5991
|
+
|
|
5992
|
+
const ZIP64_TOTAL_NUMBER_OF_DISKS = 1;
|
|
5993
|
+
|
|
5994
|
+
const EXTRAFIELD_TYPE_ZIP64 = 0x0001;
|
|
5995
|
+
const EXTRAFIELD_TYPE_AES = 0x9901;
|
|
5996
|
+
const EXTRAFIELD_TYPE_NTFS = 0x000a;
|
|
5997
|
+
const EXTRAFIELD_TYPE_NTFS_TAG1 = 0x0001;
|
|
5998
|
+
const EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP = 0x5455;
|
|
5999
|
+
const EXTRAFIELD_TYPE_UNICODE_PATH = 0x7075;
|
|
6000
|
+
const EXTRAFIELD_TYPE_UNICODE_COMMENT = 0x6375;
|
|
6001
|
+
|
|
6002
|
+
const BITFLAG_ENCRYPTED = 0x01;
|
|
6003
|
+
const BITFLAG_LEVEL = 0x06;
|
|
6004
|
+
const BITFLAG_DATA_DESCRIPTOR = 0x0008;
|
|
6005
|
+
const BITFLAG_LANG_ENCODING_FLAG = 0x0800;
|
|
6006
|
+
const FILE_ATTR_MSDOS_DIR_MASK = 0x10;
|
|
6007
|
+
|
|
6008
|
+
const VERSION_DEFLATE = 0x14;
|
|
6009
|
+
const VERSION_ZIP64 = 0x2D;
|
|
6010
|
+
const VERSION_AES = 0x33;
|
|
6011
|
+
|
|
6012
|
+
const DIRECTORY_SIGNATURE = "/";
|
|
6013
|
+
|
|
6014
|
+
const MAX_DATE = new Date(2107, 11, 31);
|
|
6015
|
+
const MIN_DATE = new Date(1980, 0, 1);
|
|
6016
|
+
|
|
5976
6017
|
const UNDEFINED_VALUE = undefined;
|
|
6018
|
+
const UNDEFINED_TYPE = "undefined";
|
|
6019
|
+
|
|
6020
|
+
/*
|
|
6021
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
6022
|
+
|
|
6023
|
+
Redistribution and use in source and binary forms, with or without
|
|
6024
|
+
modification, are permitted provided that the following conditions are met:
|
|
6025
|
+
|
|
6026
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
6027
|
+
this list of conditions and the following disclaimer.
|
|
6028
|
+
|
|
6029
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
6030
|
+
notice, this list of conditions and the following disclaimer in
|
|
6031
|
+
the documentation and/or other materials provided with the distribution.
|
|
6032
|
+
|
|
6033
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
6034
|
+
derived from this software without specific prior written permission.
|
|
6035
|
+
|
|
6036
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
6037
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
6038
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
6039
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
6040
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
6041
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
6042
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
6043
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
6044
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
6045
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
6046
|
+
*/
|
|
6047
|
+
|
|
6048
|
+
const MINIMUM_CHUNK_SIZE = 64;
|
|
5977
6049
|
let maxWorkers = 2;
|
|
5978
6050
|
try {
|
|
5979
|
-
if (typeof navigator !=
|
|
6051
|
+
if (typeof navigator != UNDEFINED_TYPE && navigator.hardwareConcurrency) {
|
|
5980
6052
|
maxWorkers = navigator.hardwareConcurrency;
|
|
5981
6053
|
}
|
|
5982
6054
|
} catch (_error) {
|
|
@@ -5988,9 +6060,9 @@
|
|
|
5988
6060
|
terminateWorkerTimeout: 5000,
|
|
5989
6061
|
useWebWorkers: true,
|
|
5990
6062
|
useCompressionStream: true,
|
|
5991
|
-
workerScripts:
|
|
5992
|
-
CompressionStreamNative: typeof CompressionStream !=
|
|
5993
|
-
DecompressionStreamNative: typeof DecompressionStream !=
|
|
6063
|
+
workerScripts: UNDEFINED_VALUE,
|
|
6064
|
+
CompressionStreamNative: typeof CompressionStream != UNDEFINED_TYPE && CompressionStream,
|
|
6065
|
+
DecompressionStreamNative: typeof DecompressionStream != UNDEFINED_TYPE && DecompressionStream
|
|
5994
6066
|
};
|
|
5995
6067
|
|
|
5996
6068
|
const config = Object.assign({}, DEFAULT_CONFIGURATION);
|
|
@@ -6217,8 +6289,8 @@
|
|
|
6217
6289
|
}
|
|
6218
6290
|
};
|
|
6219
6291
|
workerData.readable = readable.pipeThrough(new TransformStream(transformer, { highWaterMark: 1, size: () => config.chunkSize }), { signal });
|
|
6220
|
-
if (workersSupported ===
|
|
6221
|
-
workersSupported = typeof Worker !=
|
|
6292
|
+
if (workersSupported === UNDEFINED_VALUE) {
|
|
6293
|
+
workersSupported = typeof Worker != UNDEFINED_TYPE;
|
|
6222
6294
|
}
|
|
6223
6295
|
return useWebWorkers && workersSupported ? createWebWorkerInterface(workerData, config) : createWorkerInterface(workerData, config);
|
|
6224
6296
|
}
|
|
@@ -6277,7 +6349,7 @@
|
|
|
6277
6349
|
const writable = new WritableStream({
|
|
6278
6350
|
async write(chunk) {
|
|
6279
6351
|
await writer.ready;
|
|
6280
|
-
await writer.write(
|
|
6352
|
+
await writer.write(chunk);
|
|
6281
6353
|
},
|
|
6282
6354
|
async close() {
|
|
6283
6355
|
writer.releaseLock();
|
|
@@ -6453,11 +6525,11 @@
|
|
|
6453
6525
|
const { options, config } = workerOptions;
|
|
6454
6526
|
const { transferStreams, useWebWorkers, useCompressionStream, codecType, compressed, signed, encrypted } = options;
|
|
6455
6527
|
const { workerScripts } = config;
|
|
6456
|
-
workerOptions.transferStreams = transferStreams || transferStreams ===
|
|
6528
|
+
workerOptions.transferStreams = transferStreams || transferStreams === UNDEFINED_VALUE;
|
|
6457
6529
|
const streamCopy = !compressed && !signed && !encrypted && !workerOptions.transferStreams;
|
|
6458
|
-
workerOptions.useWebWorkers = !streamCopy && (useWebWorkers || (useWebWorkers ===
|
|
6530
|
+
workerOptions.useWebWorkers = !streamCopy && (useWebWorkers || (useWebWorkers === UNDEFINED_VALUE && config.useWebWorkers));
|
|
6459
6531
|
workerOptions.scripts = workerOptions.useWebWorkers && workerScripts ? workerScripts[codecType] : [];
|
|
6460
|
-
options.useCompressionStream = useCompressionStream || (useCompressionStream ===
|
|
6532
|
+
options.useCompressionStream = useCompressionStream || (useCompressionStream === UNDEFINED_VALUE && config.useCompressionStream);
|
|
6461
6533
|
let worker;
|
|
6462
6534
|
if (pool.length < config.maxWorkers) {
|
|
6463
6535
|
const workerData = { indexWorker };
|
|
@@ -6547,11 +6619,14 @@
|
|
|
6547
6619
|
const HTTP_HEADER_CONTENT_RANGE = "Content-Range";
|
|
6548
6620
|
const HTTP_HEADER_ACCEPT_RANGES = "Accept-Ranges";
|
|
6549
6621
|
const HTTP_HEADER_RANGE = "Range";
|
|
6622
|
+
const HTTP_HEADER_CONTENT_TYPE = "Content-Type";
|
|
6550
6623
|
const HTTP_METHOD_HEAD = "HEAD";
|
|
6551
6624
|
const HTTP_METHOD_GET = "GET";
|
|
6552
6625
|
const HTTP_RANGE_UNIT = "bytes";
|
|
6553
6626
|
const DEFAULT_CHUNK_SIZE = 64 * 1024;
|
|
6554
6627
|
|
|
6628
|
+
const PROPERTY_NAME_WRITABLE = "writable";
|
|
6629
|
+
|
|
6555
6630
|
class Stream {
|
|
6556
6631
|
|
|
6557
6632
|
constructor() {
|
|
@@ -6597,7 +6672,7 @@
|
|
|
6597
6672
|
return writer.writeUint8Array(chunk);
|
|
6598
6673
|
}
|
|
6599
6674
|
});
|
|
6600
|
-
Object.defineProperty(writer,
|
|
6675
|
+
Object.defineProperty(writer, PROPERTY_NAME_WRITABLE, {
|
|
6601
6676
|
get() {
|
|
6602
6677
|
return writable;
|
|
6603
6678
|
}
|
|
@@ -6613,21 +6688,26 @@
|
|
|
6613
6688
|
|
|
6614
6689
|
constructor(dataURI) {
|
|
6615
6690
|
super();
|
|
6616
|
-
const reader = this;
|
|
6617
|
-
reader.dataURI = dataURI;
|
|
6618
6691
|
let dataEnd = dataURI.length;
|
|
6619
6692
|
while (dataURI.charAt(dataEnd - 1) == "=") {
|
|
6620
6693
|
dataEnd--;
|
|
6621
6694
|
}
|
|
6622
|
-
|
|
6623
|
-
|
|
6695
|
+
const dataStart = dataURI.indexOf(",") + 1;
|
|
6696
|
+
Object.assign(this, {
|
|
6697
|
+
dataURI,
|
|
6698
|
+
dataStart,
|
|
6699
|
+
size: Math.floor((dataEnd - dataStart) * 0.75)
|
|
6700
|
+
});
|
|
6624
6701
|
}
|
|
6625
6702
|
|
|
6626
6703
|
readUint8Array(offset, length) {
|
|
6704
|
+
const {
|
|
6705
|
+
dataStart,
|
|
6706
|
+
dataURI
|
|
6707
|
+
} = this;
|
|
6627
6708
|
const dataArray = new Uint8Array(length);
|
|
6628
6709
|
const start = Math.floor(offset / 3) * 4;
|
|
6629
|
-
const
|
|
6630
|
-
const bytes = atob(this.dataURI.substring(start + dataStart, Math.ceil((offset + length) / 3) * 4 + dataStart));
|
|
6710
|
+
const bytes = atob(dataURI.substring(start + dataStart, Math.ceil((offset + length) / 3) * 4 + dataStart));
|
|
6631
6711
|
const delta = offset - Math.floor(start / 4) * 3;
|
|
6632
6712
|
for (let indexByte = delta; indexByte < delta + length; indexByte++) {
|
|
6633
6713
|
dataArray[indexByte - delta] = bytes.charCodeAt(indexByte);
|
|
@@ -6640,8 +6720,10 @@
|
|
|
6640
6720
|
|
|
6641
6721
|
constructor(contentType) {
|
|
6642
6722
|
super();
|
|
6643
|
-
|
|
6644
|
-
|
|
6723
|
+
Object.assign(this, {
|
|
6724
|
+
data: "data:" + (contentType || "") + ";base64,",
|
|
6725
|
+
pending: []
|
|
6726
|
+
});
|
|
6645
6727
|
}
|
|
6646
6728
|
|
|
6647
6729
|
writeUint8Array(array) {
|
|
@@ -6672,8 +6754,10 @@
|
|
|
6672
6754
|
|
|
6673
6755
|
constructor(blob) {
|
|
6674
6756
|
super();
|
|
6675
|
-
this
|
|
6676
|
-
|
|
6757
|
+
Object.assign(this, {
|
|
6758
|
+
blob,
|
|
6759
|
+
size: blob.size
|
|
6760
|
+
});
|
|
6677
6761
|
}
|
|
6678
6762
|
|
|
6679
6763
|
async readUint8Array(offset, length) {
|
|
@@ -6690,9 +6774,9 @@
|
|
|
6690
6774
|
const transformStream = new TransformStream();
|
|
6691
6775
|
const headers = [];
|
|
6692
6776
|
if (contentType) {
|
|
6693
|
-
headers.push([
|
|
6777
|
+
headers.push([HTTP_HEADER_CONTENT_TYPE, contentType]);
|
|
6694
6778
|
}
|
|
6695
|
-
Object.defineProperty(writer,
|
|
6779
|
+
Object.defineProperty(writer, PROPERTY_NAME_WRITABLE, {
|
|
6696
6780
|
get() {
|
|
6697
6781
|
return transformStream.writable;
|
|
6698
6782
|
}
|
|
@@ -6733,8 +6817,10 @@
|
|
|
6733
6817
|
} else {
|
|
6734
6818
|
const reader = new FileReader();
|
|
6735
6819
|
return new Promise((resolve, reject) => {
|
|
6736
|
-
reader
|
|
6737
|
-
|
|
6820
|
+
Object.assign(reader, {
|
|
6821
|
+
onload: ({ target }) => resolve(target.result),
|
|
6822
|
+
onerror: () => reject(reader.error)
|
|
6823
|
+
});
|
|
6738
6824
|
reader.readAsText(blob, encoding);
|
|
6739
6825
|
});
|
|
6740
6826
|
}
|
|
@@ -6745,16 +6831,7 @@
|
|
|
6745
6831
|
|
|
6746
6832
|
constructor(url, options) {
|
|
6747
6833
|
super();
|
|
6748
|
-
|
|
6749
|
-
reader.url = url;
|
|
6750
|
-
reader.preventHeadRequest = options.preventHeadRequest;
|
|
6751
|
-
reader.useRangeHeader = options.useRangeHeader;
|
|
6752
|
-
reader.forceRangeRequests = options.forceRangeRequests;
|
|
6753
|
-
reader.options = options = Object.assign({}, options);
|
|
6754
|
-
delete options.preventHeadRequest;
|
|
6755
|
-
delete options.useRangeHeader;
|
|
6756
|
-
delete options.forceRangeRequests;
|
|
6757
|
-
delete options.useXHR;
|
|
6834
|
+
createHtpReader(this, url, options);
|
|
6758
6835
|
}
|
|
6759
6836
|
|
|
6760
6837
|
async init() {
|
|
@@ -6771,12 +6848,7 @@
|
|
|
6771
6848
|
|
|
6772
6849
|
constructor(url, options) {
|
|
6773
6850
|
super();
|
|
6774
|
-
|
|
6775
|
-
reader.url = url;
|
|
6776
|
-
reader.preventHeadRequest = options.preventHeadRequest;
|
|
6777
|
-
reader.useRangeHeader = options.useRangeHeader;
|
|
6778
|
-
reader.forceRangeRequests = options.forceRangeRequests;
|
|
6779
|
-
reader.options = options;
|
|
6851
|
+
createHtpReader(this, url, options);
|
|
6780
6852
|
}
|
|
6781
6853
|
|
|
6782
6854
|
async init() {
|
|
@@ -6789,14 +6861,39 @@
|
|
|
6789
6861
|
}
|
|
6790
6862
|
}
|
|
6791
6863
|
|
|
6864
|
+
function createHtpReader(httpReader, url, options) {
|
|
6865
|
+
const {
|
|
6866
|
+
preventHeadRequest,
|
|
6867
|
+
useRangeHeader,
|
|
6868
|
+
forceRangeRequests
|
|
6869
|
+
} = options;
|
|
6870
|
+
options = Object.assign({}, options);
|
|
6871
|
+
delete options.preventHeadRequest;
|
|
6872
|
+
delete options.useRangeHeader;
|
|
6873
|
+
delete options.forceRangeRequests;
|
|
6874
|
+
delete options.useXHR;
|
|
6875
|
+
Object.assign(httpReader, {
|
|
6876
|
+
url,
|
|
6877
|
+
options,
|
|
6878
|
+
preventHeadRequest,
|
|
6879
|
+
useRangeHeader,
|
|
6880
|
+
forceRangeRequests
|
|
6881
|
+
});
|
|
6882
|
+
}
|
|
6883
|
+
|
|
6792
6884
|
async function initHttpReader(httpReader, sendRequest, getRequestData) {
|
|
6793
|
-
|
|
6794
|
-
|
|
6795
|
-
|
|
6885
|
+
const {
|
|
6886
|
+
url,
|
|
6887
|
+
useRangeHeader,
|
|
6888
|
+
forceRangeRequests
|
|
6889
|
+
} = httpReader;
|
|
6890
|
+
if (isHttpFamily(url) && (useRangeHeader || forceRangeRequests)) {
|
|
6891
|
+
const { headers } = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader));
|
|
6892
|
+
if (!forceRangeRequests && headers.get(HTTP_HEADER_ACCEPT_RANGES) != HTTP_RANGE_UNIT) {
|
|
6796
6893
|
throw new Error(ERR_HTTP_RANGE);
|
|
6797
6894
|
} else {
|
|
6798
6895
|
let contentSize;
|
|
6799
|
-
const contentRangeHeader =
|
|
6896
|
+
const contentRangeHeader = headers.get(HTTP_HEADER_CONTENT_RANGE);
|
|
6800
6897
|
if (contentRangeHeader) {
|
|
6801
6898
|
const splitHeader = contentRangeHeader.trim().split(/\s*\/\s*/);
|
|
6802
6899
|
if (splitHeader.length) {
|
|
@@ -6806,7 +6903,7 @@
|
|
|
6806
6903
|
}
|
|
6807
6904
|
}
|
|
6808
6905
|
}
|
|
6809
|
-
if (contentSize ===
|
|
6906
|
+
if (contentSize === UNDEFINED_VALUE) {
|
|
6810
6907
|
await getContentLength(httpReader, sendRequest, getRequestData);
|
|
6811
6908
|
} else {
|
|
6812
6909
|
httpReader.size = contentSize;
|
|
@@ -6818,17 +6915,23 @@
|
|
|
6818
6915
|
}
|
|
6819
6916
|
|
|
6820
6917
|
async function readUint8ArrayHttpReader(httpReader, index, length, sendRequest, getRequestData) {
|
|
6821
|
-
|
|
6918
|
+
const {
|
|
6919
|
+
data,
|
|
6920
|
+
useRangeHeader,
|
|
6921
|
+
forceRangeRequests,
|
|
6922
|
+
options
|
|
6923
|
+
} = httpReader;
|
|
6924
|
+
if (useRangeHeader || forceRangeRequests) {
|
|
6822
6925
|
const response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader, index, length));
|
|
6823
6926
|
if (response.status != 206) {
|
|
6824
6927
|
throw new Error(ERR_HTTP_RANGE);
|
|
6825
6928
|
}
|
|
6826
6929
|
return new Uint8Array(await response.arrayBuffer());
|
|
6827
6930
|
} else {
|
|
6828
|
-
if (!
|
|
6829
|
-
await getRequestData(httpReader,
|
|
6931
|
+
if (!data) {
|
|
6932
|
+
await getRequestData(httpReader, options);
|
|
6830
6933
|
}
|
|
6831
|
-
return new Uint8Array(
|
|
6934
|
+
return new Uint8Array(data.subarray(index, index + length));
|
|
6832
6935
|
}
|
|
6833
6936
|
}
|
|
6834
6937
|
|
|
@@ -6836,8 +6939,8 @@
|
|
|
6836
6939
|
return Object.assign({}, getHeaders(httpReader), { [HTTP_HEADER_RANGE]: HTTP_RANGE_UNIT + "=" + index + "-" + (index + length - 1) });
|
|
6837
6940
|
}
|
|
6838
6941
|
|
|
6839
|
-
function getHeaders(
|
|
6840
|
-
const headers =
|
|
6942
|
+
function getHeaders({ options }) {
|
|
6943
|
+
const { headers } = options;
|
|
6841
6944
|
if (headers) {
|
|
6842
6945
|
if (Symbol.iterator in headers) {
|
|
6843
6946
|
return Object.fromEntries(headers);
|
|
@@ -6922,9 +7025,10 @@
|
|
|
6922
7025
|
|
|
6923
7026
|
constructor(url, options = {}) {
|
|
6924
7027
|
super();
|
|
6925
|
-
|
|
6926
|
-
|
|
6927
|
-
|
|
7028
|
+
Object.assign(this, {
|
|
7029
|
+
url,
|
|
7030
|
+
reader: options.useXHR ? new XHRReader(url, options) : new FetchReader(url, options)
|
|
7031
|
+
});
|
|
6928
7032
|
}
|
|
6929
7033
|
|
|
6930
7034
|
set size(value) {
|
|
@@ -6958,8 +7062,10 @@
|
|
|
6958
7062
|
|
|
6959
7063
|
constructor(array) {
|
|
6960
7064
|
super();
|
|
6961
|
-
this
|
|
6962
|
-
|
|
7065
|
+
Object.assign(this, {
|
|
7066
|
+
array,
|
|
7067
|
+
size: array.length
|
|
7068
|
+
});
|
|
6963
7069
|
}
|
|
6964
7070
|
|
|
6965
7071
|
readUint8Array(index, length) {
|
|
@@ -6971,9 +7077,10 @@
|
|
|
6971
7077
|
|
|
6972
7078
|
init(initSize = 0) {
|
|
6973
7079
|
super.init();
|
|
6974
|
-
|
|
6975
|
-
|
|
6976
|
-
|
|
7080
|
+
Object.assign(this, {
|
|
7081
|
+
offset: 0,
|
|
7082
|
+
array: new Uint8Array(initSize)
|
|
7083
|
+
});
|
|
6977
7084
|
}
|
|
6978
7085
|
|
|
6979
7086
|
writeUint8Array(array) {
|
|
@@ -7054,76 +7161,6 @@
|
|
|
7054
7161
|
return reader.readUint8Array(offset, size, diskNumber);
|
|
7055
7162
|
}
|
|
7056
7163
|
|
|
7057
|
-
/*
|
|
7058
|
-
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
7059
|
-
|
|
7060
|
-
Redistribution and use in source and binary forms, with or without
|
|
7061
|
-
modification, are permitted provided that the following conditions are met:
|
|
7062
|
-
|
|
7063
|
-
1. Redistributions of source code must retain the above copyright notice,
|
|
7064
|
-
this list of conditions and the following disclaimer.
|
|
7065
|
-
|
|
7066
|
-
2. Redistributions in binary form must reproduce the above copyright
|
|
7067
|
-
notice, this list of conditions and the following disclaimer in
|
|
7068
|
-
the documentation and/or other materials provided with the distribution.
|
|
7069
|
-
|
|
7070
|
-
3. The names of the authors may not be used to endorse or promote products
|
|
7071
|
-
derived from this software without specific prior written permission.
|
|
7072
|
-
|
|
7073
|
-
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
7074
|
-
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
7075
|
-
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
7076
|
-
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
7077
|
-
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
7078
|
-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
7079
|
-
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
7080
|
-
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
7081
|
-
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
7082
|
-
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
7083
|
-
*/
|
|
7084
|
-
|
|
7085
|
-
const MAX_32_BITS = 0xffffffff;
|
|
7086
|
-
const MAX_16_BITS = 0xffff;
|
|
7087
|
-
const COMPRESSION_METHOD_DEFLATE = 0x08;
|
|
7088
|
-
const COMPRESSION_METHOD_STORE = 0x00;
|
|
7089
|
-
const COMPRESSION_METHOD_AES = 0x63;
|
|
7090
|
-
|
|
7091
|
-
const LOCAL_FILE_HEADER_SIGNATURE = 0x04034b50;
|
|
7092
|
-
const DATA_DESCRIPTOR_RECORD_SIGNATURE = 0x08074b50;
|
|
7093
|
-
const CENTRAL_FILE_HEADER_SIGNATURE = 0x02014b50;
|
|
7094
|
-
const END_OF_CENTRAL_DIR_SIGNATURE = 0x06054b50;
|
|
7095
|
-
const ZIP64_END_OF_CENTRAL_DIR_SIGNATURE = 0x06064b50;
|
|
7096
|
-
const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE = 0x07064b50;
|
|
7097
|
-
const END_OF_CENTRAL_DIR_LENGTH = 22;
|
|
7098
|
-
const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH = 20;
|
|
7099
|
-
const ZIP64_END_OF_CENTRAL_DIR_LENGTH = 56;
|
|
7100
|
-
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;
|
|
7101
|
-
|
|
7102
|
-
const ZIP64_TOTAL_NUMBER_OF_DISKS = 1;
|
|
7103
|
-
|
|
7104
|
-
const EXTRAFIELD_TYPE_ZIP64 = 0x0001;
|
|
7105
|
-
const EXTRAFIELD_TYPE_AES = 0x9901;
|
|
7106
|
-
const EXTRAFIELD_TYPE_NTFS = 0x000a;
|
|
7107
|
-
const EXTRAFIELD_TYPE_NTFS_TAG1 = 0x0001;
|
|
7108
|
-
const EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP = 0x5455;
|
|
7109
|
-
const EXTRAFIELD_TYPE_UNICODE_PATH = 0x7075;
|
|
7110
|
-
const EXTRAFIELD_TYPE_UNICODE_COMMENT = 0x6375;
|
|
7111
|
-
|
|
7112
|
-
const BITFLAG_ENCRYPTED = 0x01;
|
|
7113
|
-
const BITFLAG_LEVEL = 0x06;
|
|
7114
|
-
const BITFLAG_DATA_DESCRIPTOR = 0x0008;
|
|
7115
|
-
const BITFLAG_LANG_ENCODING_FLAG = 0x0800;
|
|
7116
|
-
const FILE_ATTR_MSDOS_DIR_MASK = 0x10;
|
|
7117
|
-
|
|
7118
|
-
const VERSION_DEFLATE = 0x14;
|
|
7119
|
-
const VERSION_ZIP64 = 0x2D;
|
|
7120
|
-
const VERSION_AES = 0x33;
|
|
7121
|
-
|
|
7122
|
-
const DIRECTORY_SIGNATURE = "/";
|
|
7123
|
-
|
|
7124
|
-
const MAX_DATE = new Date(2107, 11, 31);
|
|
7125
|
-
const MIN_DATE = new Date(1980, 0, 1);
|
|
7126
|
-
|
|
7127
7164
|
/*
|
|
7128
7165
|
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
7129
7166
|
|
|
@@ -7328,7 +7365,7 @@
|
|
|
7328
7365
|
let { reader } = zipReader;
|
|
7329
7366
|
const { config } = zipReader;
|
|
7330
7367
|
await initStream(reader);
|
|
7331
|
-
if (reader.size ===
|
|
7368
|
+
if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
|
|
7332
7369
|
if (Array.isArray(reader)) {
|
|
7333
7370
|
reader = new SplitZipReader(reader);
|
|
7334
7371
|
} else {
|
|
@@ -7358,7 +7395,7 @@
|
|
|
7358
7395
|
const commentLength = getUint16(endOfDirectoryView, 20);
|
|
7359
7396
|
const appendedDataOffset = commentOffset + END_OF_CENTRAL_DIR_LENGTH + commentLength;
|
|
7360
7397
|
let diskNumber = getUint16(endOfDirectoryView, 4);
|
|
7361
|
-
if (lastDiskNumber !==
|
|
7398
|
+
if (lastDiskNumber !== UNDEFINED_VALUE && diskNumber != lastDiskNumber) {
|
|
7362
7399
|
throw new Error(ERR_SPLIT_ZIP_FILE);
|
|
7363
7400
|
}
|
|
7364
7401
|
let filesLength = getUint16(endOfDirectoryView, 8);
|
|
@@ -7543,8 +7580,9 @@
|
|
|
7543
7580
|
throw new Error(ERR_LOCAL_FILE_HEADER_NOT_FOUND);
|
|
7544
7581
|
}
|
|
7545
7582
|
readCommonHeader(localDirectory, dataView, 4);
|
|
7546
|
-
|
|
7547
|
-
|
|
7583
|
+
localDirectory.rawExtraField = localDirectory.extraFieldLength ?
|
|
7584
|
+
await readUint8Array(reader, offset + 30 + localDirectory.filenameLength, localDirectory.extraFieldLength, diskNumberStart) :
|
|
7585
|
+
new Uint8Array();
|
|
7548
7586
|
await readCommonFooter(zipEntry, localDirectory, dataView, 4);
|
|
7549
7587
|
Object.assign(fileEntry, {
|
|
7550
7588
|
lastAccessDate: localDirectory.lastAccessDate,
|
|
@@ -7553,7 +7591,7 @@
|
|
|
7553
7591
|
const encrypted = zipEntry.encrypted && localDirectory.encrypted;
|
|
7554
7592
|
const zipCrypto = encrypted && !extraFieldAES;
|
|
7555
7593
|
if (encrypted) {
|
|
7556
|
-
if (!zipCrypto && extraFieldAES.strength ===
|
|
7594
|
+
if (!zipCrypto && extraFieldAES.strength === UNDEFINED_VALUE) {
|
|
7557
7595
|
throw new Error(ERR_UNSUPPORTED_ENCRYPTION);
|
|
7558
7596
|
} else if (!password) {
|
|
7559
7597
|
throw new Error(ERR_ENCRYPTED);
|
|
@@ -7570,7 +7608,7 @@
|
|
|
7570
7608
|
};
|
|
7571
7609
|
}
|
|
7572
7610
|
const { writable } = writer;
|
|
7573
|
-
if (writable.size ===
|
|
7611
|
+
if (writable.size === UNDEFINED_VALUE) {
|
|
7574
7612
|
writable.size = 0;
|
|
7575
7613
|
}
|
|
7576
7614
|
const signal = getOptionValue$1(zipEntry, options, "signal");
|
|
@@ -7818,7 +7856,7 @@
|
|
|
7818
7856
|
}
|
|
7819
7857
|
|
|
7820
7858
|
function getOptionValue$1(zipReader, options, name) {
|
|
7821
|
-
return options[name] ===
|
|
7859
|
+
return options[name] === UNDEFINED_VALUE ? zipReader.options[name] : options[name];
|
|
7822
7860
|
}
|
|
7823
7861
|
|
|
7824
7862
|
function getDate(timeRaw) {
|
|
@@ -7908,7 +7946,7 @@
|
|
|
7908
7946
|
if (writer instanceof WritableStream) {
|
|
7909
7947
|
writer = { writable: writer };
|
|
7910
7948
|
}
|
|
7911
|
-
if (writer.writable.size ===
|
|
7949
|
+
if (writer.writable.size === UNDEFINED_VALUE) {
|
|
7912
7950
|
writer.writable.size = 0;
|
|
7913
7951
|
}
|
|
7914
7952
|
Object.assign(this, {
|
|
@@ -8002,7 +8040,7 @@
|
|
|
8002
8040
|
const password = getOptionValue(zipWriter, options, "password");
|
|
8003
8041
|
const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength") || 3;
|
|
8004
8042
|
const zipCrypto = getOptionValue(zipWriter, options, "zipCrypto");
|
|
8005
|
-
if (password !==
|
|
8043
|
+
if (password !== UNDEFINED_VALUE && encryptionStrength !== UNDEFINED_VALUE && (encryptionStrength < 1 || encryptionStrength > 3)) {
|
|
8006
8044
|
throw new Error(ERR_INVALID_ENCRYPTION_STRENGTH);
|
|
8007
8045
|
}
|
|
8008
8046
|
let rawExtraField = new Uint8Array();
|
|
@@ -8026,18 +8064,18 @@
|
|
|
8026
8064
|
});
|
|
8027
8065
|
}
|
|
8028
8066
|
let extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp");
|
|
8029
|
-
if (extendedTimestamp ===
|
|
8067
|
+
if (extendedTimestamp === UNDEFINED_VALUE) {
|
|
8030
8068
|
extendedTimestamp = true;
|
|
8031
8069
|
}
|
|
8032
8070
|
let maximumCompressedSize = 0;
|
|
8033
8071
|
let maximumEntrySize = 0;
|
|
8034
8072
|
let keepOrder = getOptionValue(zipWriter, options, "keepOrder");
|
|
8035
|
-
if (keepOrder ===
|
|
8073
|
+
if (keepOrder === UNDEFINED_VALUE) {
|
|
8036
8074
|
keepOrder = true;
|
|
8037
8075
|
}
|
|
8038
8076
|
let uncompressedSize = 0;
|
|
8039
8077
|
let msDosCompatible = getOptionValue(zipWriter, options, "msDosCompatible");
|
|
8040
|
-
if (msDosCompatible ===
|
|
8078
|
+
if (msDosCompatible === UNDEFINED_VALUE) {
|
|
8041
8079
|
msDosCompatible = true;
|
|
8042
8080
|
}
|
|
8043
8081
|
const internalFileAttribute = getOptionValue(zipWriter, options, "internalFileAttribute") || 0;
|
|
@@ -8050,15 +8088,16 @@
|
|
|
8050
8088
|
};
|
|
8051
8089
|
}
|
|
8052
8090
|
await initStream(reader);
|
|
8053
|
-
if (reader.size ===
|
|
8091
|
+
if (reader.size === UNDEFINED_VALUE) {
|
|
8054
8092
|
options.dataDescriptor = true;
|
|
8055
|
-
if (zip64 ===
|
|
8093
|
+
if (zip64 || zip64 === UNDEFINED_VALUE) {
|
|
8056
8094
|
zip64 = true;
|
|
8095
|
+
maximumCompressedSize = MAX_32_BITS;
|
|
8057
8096
|
}
|
|
8058
8097
|
} else {
|
|
8059
8098
|
uncompressedSize = reader.size;
|
|
8099
|
+
maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
|
|
8060
8100
|
}
|
|
8061
|
-
maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
|
|
8062
8101
|
}
|
|
8063
8102
|
if (zipWriter.offset + zipWriter.pendingEntriesSize >= MAX_32_BITS ||
|
|
8064
8103
|
uncompressedSize >= MAX_32_BITS ||
|
|
@@ -8077,10 +8116,10 @@
|
|
|
8077
8116
|
let dataDescriptorSignature = getOptionValue(zipWriter, options, "dataDescriptorSignature");
|
|
8078
8117
|
const signal = getOptionValue(zipWriter, options, "signal");
|
|
8079
8118
|
const useCompressionStream = getOptionValue(zipWriter, options, "useCompressionStream");
|
|
8080
|
-
if (dataDescriptor ===
|
|
8119
|
+
if (dataDescriptor === UNDEFINED_VALUE) {
|
|
8081
8120
|
dataDescriptor = true;
|
|
8082
8121
|
}
|
|
8083
|
-
if (dataDescriptor && dataDescriptorSignature ===
|
|
8122
|
+
if (dataDescriptor && dataDescriptorSignature === UNDEFINED_VALUE) {
|
|
8084
8123
|
dataDescriptorSignature = false;
|
|
8085
8124
|
}
|
|
8086
8125
|
options = Object.assign({}, options, {
|
|
@@ -8547,7 +8586,7 @@
|
|
|
8547
8586
|
zipCrypto,
|
|
8548
8587
|
dataDescriptor
|
|
8549
8588
|
} = options;
|
|
8550
|
-
if ((!encrypted || zipCrypto) && signature !==
|
|
8589
|
+
if ((!encrypted || zipCrypto) && signature !== UNDEFINED_VALUE) {
|
|
8551
8590
|
setUint32(headerView, 10, signature);
|
|
8552
8591
|
if (dataDescriptor) {
|
|
8553
8592
|
setUint32(dataDescriptorView, dataDescriptorOffset, signature);
|
|
@@ -8734,7 +8773,7 @@
|
|
|
8734
8773
|
}
|
|
8735
8774
|
|
|
8736
8775
|
function getOptionValue(zipWriter, options, name) {
|
|
8737
|
-
return options[name] ===
|
|
8776
|
+
return options[name] === UNDEFINED_VALUE ? zipWriter.options[name] : options[name];
|
|
8738
8777
|
}
|
|
8739
8778
|
|
|
8740
8779
|
function getMaximumCompressedSize(uncompressedSize) {
|