@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/index.cjs
CHANGED
|
@@ -5277,11 +5277,11 @@ const SALT_LENGTH = [8, 12, 16];
|
|
|
5277
5277
|
const KEY_LENGTH = [16, 24, 32];
|
|
5278
5278
|
const SIGNATURE_LENGTH = 10;
|
|
5279
5279
|
const COUNTER_DEFAULT_VALUE = [0, 0, 0, 0];
|
|
5280
|
-
const UNDEFINED_TYPE = "undefined";
|
|
5280
|
+
const UNDEFINED_TYPE$1 = "undefined";
|
|
5281
5281
|
const FUNCTION_TYPE = "function";
|
|
5282
|
-
const CRYPTO_API_SUPPORTED = typeof crypto != UNDEFINED_TYPE;
|
|
5282
|
+
const CRYPTO_API_SUPPORTED = typeof crypto != UNDEFINED_TYPE$1;
|
|
5283
5283
|
const subtle = CRYPTO_API_SUPPORTED && crypto.subtle;
|
|
5284
|
-
const SUBTLE_API_SUPPORTED = CRYPTO_API_SUPPORTED && typeof subtle != UNDEFINED_TYPE;
|
|
5284
|
+
const SUBTLE_API_SUPPORTED = CRYPTO_API_SUPPORTED && typeof subtle != UNDEFINED_TYPE$1;
|
|
5285
5285
|
const IMPORT_KEY_SUPPORTED = CRYPTO_API_SUPPORTED && SUBTLE_API_SUPPORTED && typeof subtle.importKey == FUNCTION_TYPE;
|
|
5286
5286
|
const DERIVE_BITS_SUPPORTED = CRYPTO_API_SUPPORTED && SUBTLE_API_SUPPORTED && typeof subtle.deriveBits == FUNCTION_TYPE;
|
|
5287
5287
|
const codecBytes = codec.bytes;
|
|
@@ -5968,11 +5968,83 @@ function getCodecStreamClass(Codec) {
|
|
|
5968
5968
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
5969
5969
|
*/
|
|
5970
5970
|
|
|
5971
|
-
const
|
|
5971
|
+
const MAX_32_BITS = 0xffffffff;
|
|
5972
|
+
const MAX_16_BITS = 0xffff;
|
|
5973
|
+
const COMPRESSION_METHOD_DEFLATE = 0x08;
|
|
5974
|
+
const COMPRESSION_METHOD_STORE = 0x00;
|
|
5975
|
+
const COMPRESSION_METHOD_AES = 0x63;
|
|
5976
|
+
|
|
5977
|
+
const LOCAL_FILE_HEADER_SIGNATURE = 0x04034b50;
|
|
5978
|
+
const DATA_DESCRIPTOR_RECORD_SIGNATURE = 0x08074b50;
|
|
5979
|
+
const CENTRAL_FILE_HEADER_SIGNATURE = 0x02014b50;
|
|
5980
|
+
const END_OF_CENTRAL_DIR_SIGNATURE = 0x06054b50;
|
|
5981
|
+
const ZIP64_END_OF_CENTRAL_DIR_SIGNATURE = 0x06064b50;
|
|
5982
|
+
const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE = 0x07064b50;
|
|
5983
|
+
const END_OF_CENTRAL_DIR_LENGTH = 22;
|
|
5984
|
+
const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH = 20;
|
|
5985
|
+
const ZIP64_END_OF_CENTRAL_DIR_LENGTH = 56;
|
|
5986
|
+
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;
|
|
5987
|
+
|
|
5988
|
+
const ZIP64_TOTAL_NUMBER_OF_DISKS = 1;
|
|
5989
|
+
|
|
5990
|
+
const EXTRAFIELD_TYPE_ZIP64 = 0x0001;
|
|
5991
|
+
const EXTRAFIELD_TYPE_AES = 0x9901;
|
|
5992
|
+
const EXTRAFIELD_TYPE_NTFS = 0x000a;
|
|
5993
|
+
const EXTRAFIELD_TYPE_NTFS_TAG1 = 0x0001;
|
|
5994
|
+
const EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP = 0x5455;
|
|
5995
|
+
const EXTRAFIELD_TYPE_UNICODE_PATH = 0x7075;
|
|
5996
|
+
const EXTRAFIELD_TYPE_UNICODE_COMMENT = 0x6375;
|
|
5997
|
+
|
|
5998
|
+
const BITFLAG_ENCRYPTED = 0x01;
|
|
5999
|
+
const BITFLAG_LEVEL = 0x06;
|
|
6000
|
+
const BITFLAG_DATA_DESCRIPTOR = 0x0008;
|
|
6001
|
+
const BITFLAG_LANG_ENCODING_FLAG = 0x0800;
|
|
6002
|
+
const FILE_ATTR_MSDOS_DIR_MASK = 0x10;
|
|
6003
|
+
|
|
6004
|
+
const VERSION_DEFLATE = 0x14;
|
|
6005
|
+
const VERSION_ZIP64 = 0x2D;
|
|
6006
|
+
const VERSION_AES = 0x33;
|
|
6007
|
+
|
|
6008
|
+
const DIRECTORY_SIGNATURE = "/";
|
|
6009
|
+
|
|
6010
|
+
const MAX_DATE = new Date(2107, 11, 31);
|
|
6011
|
+
const MIN_DATE = new Date(1980, 0, 1);
|
|
6012
|
+
|
|
5972
6013
|
const UNDEFINED_VALUE = undefined;
|
|
6014
|
+
const UNDEFINED_TYPE = "undefined";
|
|
6015
|
+
|
|
6016
|
+
/*
|
|
6017
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
6018
|
+
|
|
6019
|
+
Redistribution and use in source and binary forms, with or without
|
|
6020
|
+
modification, are permitted provided that the following conditions are met:
|
|
6021
|
+
|
|
6022
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
6023
|
+
this list of conditions and the following disclaimer.
|
|
6024
|
+
|
|
6025
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
6026
|
+
notice, this list of conditions and the following disclaimer in
|
|
6027
|
+
the documentation and/or other materials provided with the distribution.
|
|
6028
|
+
|
|
6029
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
6030
|
+
derived from this software without specific prior written permission.
|
|
6031
|
+
|
|
6032
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
6033
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
6034
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
6035
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
6036
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
6037
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
6038
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
6039
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
6040
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
6041
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
6042
|
+
*/
|
|
6043
|
+
|
|
6044
|
+
const MINIMUM_CHUNK_SIZE = 64;
|
|
5973
6045
|
let maxWorkers = 2;
|
|
5974
6046
|
try {
|
|
5975
|
-
if (typeof navigator !=
|
|
6047
|
+
if (typeof navigator != UNDEFINED_TYPE && navigator.hardwareConcurrency) {
|
|
5976
6048
|
maxWorkers = navigator.hardwareConcurrency;
|
|
5977
6049
|
}
|
|
5978
6050
|
} catch (_error) {
|
|
@@ -5984,9 +6056,9 @@ const DEFAULT_CONFIGURATION = {
|
|
|
5984
6056
|
terminateWorkerTimeout: 5000,
|
|
5985
6057
|
useWebWorkers: true,
|
|
5986
6058
|
useCompressionStream: true,
|
|
5987
|
-
workerScripts:
|
|
5988
|
-
CompressionStreamNative: typeof CompressionStream !=
|
|
5989
|
-
DecompressionStreamNative: typeof DecompressionStream !=
|
|
6059
|
+
workerScripts: UNDEFINED_VALUE,
|
|
6060
|
+
CompressionStreamNative: typeof CompressionStream != UNDEFINED_TYPE && CompressionStream,
|
|
6061
|
+
DecompressionStreamNative: typeof DecompressionStream != UNDEFINED_TYPE && DecompressionStream
|
|
5990
6062
|
};
|
|
5991
6063
|
|
|
5992
6064
|
const config = Object.assign({}, DEFAULT_CONFIGURATION);
|
|
@@ -7163,8 +7235,8 @@ class CodecWorker {
|
|
|
7163
7235
|
}
|
|
7164
7236
|
};
|
|
7165
7237
|
workerData.readable = readable.pipeThrough(new TransformStream(transformer, { highWaterMark: 1, size: () => config.chunkSize }), { signal });
|
|
7166
|
-
if (workersSupported ===
|
|
7167
|
-
workersSupported = typeof Worker !=
|
|
7238
|
+
if (workersSupported === UNDEFINED_VALUE) {
|
|
7239
|
+
workersSupported = typeof Worker != UNDEFINED_TYPE;
|
|
7168
7240
|
}
|
|
7169
7241
|
return useWebWorkers && workersSupported ? createWebWorkerInterface(workerData, config) : createWorkerInterface(workerData, config);
|
|
7170
7242
|
}
|
|
@@ -7223,7 +7295,7 @@ function createWebWorkerInterface(workerData, { baseURL, chunkSize }) {
|
|
|
7223
7295
|
const writable = new WritableStream({
|
|
7224
7296
|
async write(chunk) {
|
|
7225
7297
|
await writer.ready;
|
|
7226
|
-
await writer.write(
|
|
7298
|
+
await writer.write(chunk);
|
|
7227
7299
|
},
|
|
7228
7300
|
async close() {
|
|
7229
7301
|
writer.releaseLock();
|
|
@@ -7399,11 +7471,11 @@ async function runWorker(stream, workerOptions) {
|
|
|
7399
7471
|
const { options, config } = workerOptions;
|
|
7400
7472
|
const { transferStreams, useWebWorkers, useCompressionStream, codecType, compressed, signed, encrypted } = options;
|
|
7401
7473
|
const { workerScripts } = config;
|
|
7402
|
-
workerOptions.transferStreams = transferStreams || transferStreams ===
|
|
7474
|
+
workerOptions.transferStreams = transferStreams || transferStreams === UNDEFINED_VALUE;
|
|
7403
7475
|
const streamCopy = !compressed && !signed && !encrypted && !workerOptions.transferStreams;
|
|
7404
|
-
workerOptions.useWebWorkers = !streamCopy && (useWebWorkers || (useWebWorkers ===
|
|
7476
|
+
workerOptions.useWebWorkers = !streamCopy && (useWebWorkers || (useWebWorkers === UNDEFINED_VALUE && config.useWebWorkers));
|
|
7405
7477
|
workerOptions.scripts = workerOptions.useWebWorkers && workerScripts ? workerScripts[codecType] : [];
|
|
7406
|
-
options.useCompressionStream = useCompressionStream || (useCompressionStream ===
|
|
7478
|
+
options.useCompressionStream = useCompressionStream || (useCompressionStream === UNDEFINED_VALUE && config.useCompressionStream);
|
|
7407
7479
|
let worker;
|
|
7408
7480
|
if (pool.length < config.maxWorkers) {
|
|
7409
7481
|
const workerData = { indexWorker };
|
|
@@ -7544,11 +7616,14 @@ const HTTP_HEADER_CONTENT_LENGTH = "Content-Length";
|
|
|
7544
7616
|
const HTTP_HEADER_CONTENT_RANGE = "Content-Range";
|
|
7545
7617
|
const HTTP_HEADER_ACCEPT_RANGES = "Accept-Ranges";
|
|
7546
7618
|
const HTTP_HEADER_RANGE = "Range";
|
|
7619
|
+
const HTTP_HEADER_CONTENT_TYPE = "Content-Type";
|
|
7547
7620
|
const HTTP_METHOD_HEAD = "HEAD";
|
|
7548
7621
|
const HTTP_METHOD_GET = "GET";
|
|
7549
7622
|
const HTTP_RANGE_UNIT = "bytes";
|
|
7550
7623
|
const DEFAULT_CHUNK_SIZE = 64 * 1024;
|
|
7551
7624
|
|
|
7625
|
+
const PROPERTY_NAME_WRITABLE = "writable";
|
|
7626
|
+
|
|
7552
7627
|
class Stream {
|
|
7553
7628
|
|
|
7554
7629
|
constructor() {
|
|
@@ -7594,7 +7669,7 @@ class Writer extends Stream {
|
|
|
7594
7669
|
return writer.writeUint8Array(chunk);
|
|
7595
7670
|
}
|
|
7596
7671
|
});
|
|
7597
|
-
Object.defineProperty(writer,
|
|
7672
|
+
Object.defineProperty(writer, PROPERTY_NAME_WRITABLE, {
|
|
7598
7673
|
get() {
|
|
7599
7674
|
return writable;
|
|
7600
7675
|
}
|
|
@@ -7610,21 +7685,26 @@ class Data64URIReader extends Reader {
|
|
|
7610
7685
|
|
|
7611
7686
|
constructor(dataURI) {
|
|
7612
7687
|
super();
|
|
7613
|
-
const reader = this;
|
|
7614
|
-
reader.dataURI = dataURI;
|
|
7615
7688
|
let dataEnd = dataURI.length;
|
|
7616
7689
|
while (dataURI.charAt(dataEnd - 1) == "=") {
|
|
7617
7690
|
dataEnd--;
|
|
7618
7691
|
}
|
|
7619
|
-
|
|
7620
|
-
|
|
7692
|
+
const dataStart = dataURI.indexOf(",") + 1;
|
|
7693
|
+
Object.assign(this, {
|
|
7694
|
+
dataURI,
|
|
7695
|
+
dataStart,
|
|
7696
|
+
size: Math.floor((dataEnd - dataStart) * 0.75)
|
|
7697
|
+
});
|
|
7621
7698
|
}
|
|
7622
7699
|
|
|
7623
7700
|
readUint8Array(offset, length) {
|
|
7701
|
+
const {
|
|
7702
|
+
dataStart,
|
|
7703
|
+
dataURI
|
|
7704
|
+
} = this;
|
|
7624
7705
|
const dataArray = new Uint8Array(length);
|
|
7625
7706
|
const start = Math.floor(offset / 3) * 4;
|
|
7626
|
-
const
|
|
7627
|
-
const bytes = atob(this.dataURI.substring(start + dataStart, Math.ceil((offset + length) / 3) * 4 + dataStart));
|
|
7707
|
+
const bytes = atob(dataURI.substring(start + dataStart, Math.ceil((offset + length) / 3) * 4 + dataStart));
|
|
7628
7708
|
const delta = offset - Math.floor(start / 4) * 3;
|
|
7629
7709
|
for (let indexByte = delta; indexByte < delta + length; indexByte++) {
|
|
7630
7710
|
dataArray[indexByte - delta] = bytes.charCodeAt(indexByte);
|
|
@@ -7637,8 +7717,10 @@ class Data64URIWriter extends Writer {
|
|
|
7637
7717
|
|
|
7638
7718
|
constructor(contentType) {
|
|
7639
7719
|
super();
|
|
7640
|
-
|
|
7641
|
-
|
|
7720
|
+
Object.assign(this, {
|
|
7721
|
+
data: "data:" + (contentType || "") + ";base64,",
|
|
7722
|
+
pending: []
|
|
7723
|
+
});
|
|
7642
7724
|
}
|
|
7643
7725
|
|
|
7644
7726
|
writeUint8Array(array) {
|
|
@@ -7669,8 +7751,10 @@ class BlobReader extends Reader {
|
|
|
7669
7751
|
|
|
7670
7752
|
constructor(blob) {
|
|
7671
7753
|
super();
|
|
7672
|
-
this
|
|
7673
|
-
|
|
7754
|
+
Object.assign(this, {
|
|
7755
|
+
blob,
|
|
7756
|
+
size: blob.size
|
|
7757
|
+
});
|
|
7674
7758
|
}
|
|
7675
7759
|
|
|
7676
7760
|
async readUint8Array(offset, length) {
|
|
@@ -7687,9 +7771,9 @@ class BlobWriter extends Stream {
|
|
|
7687
7771
|
const transformStream = new TransformStream();
|
|
7688
7772
|
const headers = [];
|
|
7689
7773
|
if (contentType) {
|
|
7690
|
-
headers.push([
|
|
7774
|
+
headers.push([HTTP_HEADER_CONTENT_TYPE, contentType]);
|
|
7691
7775
|
}
|
|
7692
|
-
Object.defineProperty(writer,
|
|
7776
|
+
Object.defineProperty(writer, PROPERTY_NAME_WRITABLE, {
|
|
7693
7777
|
get() {
|
|
7694
7778
|
return transformStream.writable;
|
|
7695
7779
|
}
|
|
@@ -7730,8 +7814,10 @@ class TextWriter extends BlobWriter {
|
|
|
7730
7814
|
} else {
|
|
7731
7815
|
const reader = new FileReader();
|
|
7732
7816
|
return new Promise((resolve, reject) => {
|
|
7733
|
-
reader
|
|
7734
|
-
|
|
7817
|
+
Object.assign(reader, {
|
|
7818
|
+
onload: ({ target }) => resolve(target.result),
|
|
7819
|
+
onerror: () => reject(reader.error)
|
|
7820
|
+
});
|
|
7735
7821
|
reader.readAsText(blob, encoding);
|
|
7736
7822
|
});
|
|
7737
7823
|
}
|
|
@@ -7742,16 +7828,7 @@ class FetchReader extends Reader {
|
|
|
7742
7828
|
|
|
7743
7829
|
constructor(url, options) {
|
|
7744
7830
|
super();
|
|
7745
|
-
|
|
7746
|
-
reader.url = url;
|
|
7747
|
-
reader.preventHeadRequest = options.preventHeadRequest;
|
|
7748
|
-
reader.useRangeHeader = options.useRangeHeader;
|
|
7749
|
-
reader.forceRangeRequests = options.forceRangeRequests;
|
|
7750
|
-
reader.options = options = Object.assign({}, options);
|
|
7751
|
-
delete options.preventHeadRequest;
|
|
7752
|
-
delete options.useRangeHeader;
|
|
7753
|
-
delete options.forceRangeRequests;
|
|
7754
|
-
delete options.useXHR;
|
|
7831
|
+
createHtpReader(this, url, options);
|
|
7755
7832
|
}
|
|
7756
7833
|
|
|
7757
7834
|
async init() {
|
|
@@ -7768,12 +7845,7 @@ class XHRReader extends Reader {
|
|
|
7768
7845
|
|
|
7769
7846
|
constructor(url, options) {
|
|
7770
7847
|
super();
|
|
7771
|
-
|
|
7772
|
-
reader.url = url;
|
|
7773
|
-
reader.preventHeadRequest = options.preventHeadRequest;
|
|
7774
|
-
reader.useRangeHeader = options.useRangeHeader;
|
|
7775
|
-
reader.forceRangeRequests = options.forceRangeRequests;
|
|
7776
|
-
reader.options = options;
|
|
7848
|
+
createHtpReader(this, url, options);
|
|
7777
7849
|
}
|
|
7778
7850
|
|
|
7779
7851
|
async init() {
|
|
@@ -7786,14 +7858,39 @@ class XHRReader extends Reader {
|
|
|
7786
7858
|
}
|
|
7787
7859
|
}
|
|
7788
7860
|
|
|
7861
|
+
function createHtpReader(httpReader, url, options) {
|
|
7862
|
+
const {
|
|
7863
|
+
preventHeadRequest,
|
|
7864
|
+
useRangeHeader,
|
|
7865
|
+
forceRangeRequests
|
|
7866
|
+
} = options;
|
|
7867
|
+
options = Object.assign({}, options);
|
|
7868
|
+
delete options.preventHeadRequest;
|
|
7869
|
+
delete options.useRangeHeader;
|
|
7870
|
+
delete options.forceRangeRequests;
|
|
7871
|
+
delete options.useXHR;
|
|
7872
|
+
Object.assign(httpReader, {
|
|
7873
|
+
url,
|
|
7874
|
+
options,
|
|
7875
|
+
preventHeadRequest,
|
|
7876
|
+
useRangeHeader,
|
|
7877
|
+
forceRangeRequests
|
|
7878
|
+
});
|
|
7879
|
+
}
|
|
7880
|
+
|
|
7789
7881
|
async function initHttpReader(httpReader, sendRequest, getRequestData) {
|
|
7790
|
-
|
|
7791
|
-
|
|
7792
|
-
|
|
7882
|
+
const {
|
|
7883
|
+
url,
|
|
7884
|
+
useRangeHeader,
|
|
7885
|
+
forceRangeRequests
|
|
7886
|
+
} = httpReader;
|
|
7887
|
+
if (isHttpFamily(url) && (useRangeHeader || forceRangeRequests)) {
|
|
7888
|
+
const { headers } = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader));
|
|
7889
|
+
if (!forceRangeRequests && headers.get(HTTP_HEADER_ACCEPT_RANGES) != HTTP_RANGE_UNIT) {
|
|
7793
7890
|
throw new Error(ERR_HTTP_RANGE);
|
|
7794
7891
|
} else {
|
|
7795
7892
|
let contentSize;
|
|
7796
|
-
const contentRangeHeader =
|
|
7893
|
+
const contentRangeHeader = headers.get(HTTP_HEADER_CONTENT_RANGE);
|
|
7797
7894
|
if (contentRangeHeader) {
|
|
7798
7895
|
const splitHeader = contentRangeHeader.trim().split(/\s*\/\s*/);
|
|
7799
7896
|
if (splitHeader.length) {
|
|
@@ -7803,7 +7900,7 @@ async function initHttpReader(httpReader, sendRequest, getRequestData) {
|
|
|
7803
7900
|
}
|
|
7804
7901
|
}
|
|
7805
7902
|
}
|
|
7806
|
-
if (contentSize ===
|
|
7903
|
+
if (contentSize === UNDEFINED_VALUE) {
|
|
7807
7904
|
await getContentLength(httpReader, sendRequest, getRequestData);
|
|
7808
7905
|
} else {
|
|
7809
7906
|
httpReader.size = contentSize;
|
|
@@ -7815,17 +7912,23 @@ async function initHttpReader(httpReader, sendRequest, getRequestData) {
|
|
|
7815
7912
|
}
|
|
7816
7913
|
|
|
7817
7914
|
async function readUint8ArrayHttpReader(httpReader, index, length, sendRequest, getRequestData) {
|
|
7818
|
-
|
|
7915
|
+
const {
|
|
7916
|
+
data,
|
|
7917
|
+
useRangeHeader,
|
|
7918
|
+
forceRangeRequests,
|
|
7919
|
+
options
|
|
7920
|
+
} = httpReader;
|
|
7921
|
+
if (useRangeHeader || forceRangeRequests) {
|
|
7819
7922
|
const response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader, index, length));
|
|
7820
7923
|
if (response.status != 206) {
|
|
7821
7924
|
throw new Error(ERR_HTTP_RANGE);
|
|
7822
7925
|
}
|
|
7823
7926
|
return new Uint8Array(await response.arrayBuffer());
|
|
7824
7927
|
} else {
|
|
7825
|
-
if (!
|
|
7826
|
-
await getRequestData(httpReader,
|
|
7928
|
+
if (!data) {
|
|
7929
|
+
await getRequestData(httpReader, options);
|
|
7827
7930
|
}
|
|
7828
|
-
return new Uint8Array(
|
|
7931
|
+
return new Uint8Array(data.subarray(index, index + length));
|
|
7829
7932
|
}
|
|
7830
7933
|
}
|
|
7831
7934
|
|
|
@@ -7833,8 +7936,8 @@ function getRangeHeaders(httpReader, index = 0, length = 1) {
|
|
|
7833
7936
|
return Object.assign({}, getHeaders(httpReader), { [HTTP_HEADER_RANGE]: HTTP_RANGE_UNIT + "=" + index + "-" + (index + length - 1) });
|
|
7834
7937
|
}
|
|
7835
7938
|
|
|
7836
|
-
function getHeaders(
|
|
7837
|
-
const headers =
|
|
7939
|
+
function getHeaders({ options }) {
|
|
7940
|
+
const { headers } = options;
|
|
7838
7941
|
if (headers) {
|
|
7839
7942
|
if (Symbol.iterator in headers) {
|
|
7840
7943
|
return Object.fromEntries(headers);
|
|
@@ -7919,9 +8022,10 @@ class HttpReader extends Reader {
|
|
|
7919
8022
|
|
|
7920
8023
|
constructor(url, options = {}) {
|
|
7921
8024
|
super();
|
|
7922
|
-
|
|
7923
|
-
|
|
7924
|
-
|
|
8025
|
+
Object.assign(this, {
|
|
8026
|
+
url,
|
|
8027
|
+
reader: options.useXHR ? new XHRReader(url, options) : new FetchReader(url, options)
|
|
8028
|
+
});
|
|
7925
8029
|
}
|
|
7926
8030
|
|
|
7927
8031
|
set size(value) {
|
|
@@ -7955,8 +8059,10 @@ class Uint8ArrayReader extends Reader {
|
|
|
7955
8059
|
|
|
7956
8060
|
constructor(array) {
|
|
7957
8061
|
super();
|
|
7958
|
-
this
|
|
7959
|
-
|
|
8062
|
+
Object.assign(this, {
|
|
8063
|
+
array,
|
|
8064
|
+
size: array.length
|
|
8065
|
+
});
|
|
7960
8066
|
}
|
|
7961
8067
|
|
|
7962
8068
|
readUint8Array(index, length) {
|
|
@@ -7968,9 +8074,10 @@ class Uint8ArrayWriter extends Writer {
|
|
|
7968
8074
|
|
|
7969
8075
|
init(initSize = 0) {
|
|
7970
8076
|
super.init();
|
|
7971
|
-
|
|
7972
|
-
|
|
7973
|
-
|
|
8077
|
+
Object.assign(this, {
|
|
8078
|
+
offset: 0,
|
|
8079
|
+
array: new Uint8Array(initSize)
|
|
8080
|
+
});
|
|
7974
8081
|
}
|
|
7975
8082
|
|
|
7976
8083
|
writeUint8Array(array) {
|
|
@@ -8051,76 +8158,6 @@ function readUint8Array(reader, offset, size, diskNumber) {
|
|
|
8051
8158
|
return reader.readUint8Array(offset, size, diskNumber);
|
|
8052
8159
|
}
|
|
8053
8160
|
|
|
8054
|
-
/*
|
|
8055
|
-
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
8056
|
-
|
|
8057
|
-
Redistribution and use in source and binary forms, with or without
|
|
8058
|
-
modification, are permitted provided that the following conditions are met:
|
|
8059
|
-
|
|
8060
|
-
1. Redistributions of source code must retain the above copyright notice,
|
|
8061
|
-
this list of conditions and the following disclaimer.
|
|
8062
|
-
|
|
8063
|
-
2. Redistributions in binary form must reproduce the above copyright
|
|
8064
|
-
notice, this list of conditions and the following disclaimer in
|
|
8065
|
-
the documentation and/or other materials provided with the distribution.
|
|
8066
|
-
|
|
8067
|
-
3. The names of the authors may not be used to endorse or promote products
|
|
8068
|
-
derived from this software without specific prior written permission.
|
|
8069
|
-
|
|
8070
|
-
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
8071
|
-
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
8072
|
-
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
8073
|
-
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
8074
|
-
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
8075
|
-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
8076
|
-
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
8077
|
-
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
8078
|
-
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
8079
|
-
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
8080
|
-
*/
|
|
8081
|
-
|
|
8082
|
-
const MAX_32_BITS = 0xffffffff;
|
|
8083
|
-
const MAX_16_BITS = 0xffff;
|
|
8084
|
-
const COMPRESSION_METHOD_DEFLATE = 0x08;
|
|
8085
|
-
const COMPRESSION_METHOD_STORE = 0x00;
|
|
8086
|
-
const COMPRESSION_METHOD_AES = 0x63;
|
|
8087
|
-
|
|
8088
|
-
const LOCAL_FILE_HEADER_SIGNATURE = 0x04034b50;
|
|
8089
|
-
const DATA_DESCRIPTOR_RECORD_SIGNATURE = 0x08074b50;
|
|
8090
|
-
const CENTRAL_FILE_HEADER_SIGNATURE = 0x02014b50;
|
|
8091
|
-
const END_OF_CENTRAL_DIR_SIGNATURE = 0x06054b50;
|
|
8092
|
-
const ZIP64_END_OF_CENTRAL_DIR_SIGNATURE = 0x06064b50;
|
|
8093
|
-
const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE = 0x07064b50;
|
|
8094
|
-
const END_OF_CENTRAL_DIR_LENGTH = 22;
|
|
8095
|
-
const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH = 20;
|
|
8096
|
-
const ZIP64_END_OF_CENTRAL_DIR_LENGTH = 56;
|
|
8097
|
-
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;
|
|
8098
|
-
|
|
8099
|
-
const ZIP64_TOTAL_NUMBER_OF_DISKS = 1;
|
|
8100
|
-
|
|
8101
|
-
const EXTRAFIELD_TYPE_ZIP64 = 0x0001;
|
|
8102
|
-
const EXTRAFIELD_TYPE_AES = 0x9901;
|
|
8103
|
-
const EXTRAFIELD_TYPE_NTFS = 0x000a;
|
|
8104
|
-
const EXTRAFIELD_TYPE_NTFS_TAG1 = 0x0001;
|
|
8105
|
-
const EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP = 0x5455;
|
|
8106
|
-
const EXTRAFIELD_TYPE_UNICODE_PATH = 0x7075;
|
|
8107
|
-
const EXTRAFIELD_TYPE_UNICODE_COMMENT = 0x6375;
|
|
8108
|
-
|
|
8109
|
-
const BITFLAG_ENCRYPTED = 0x01;
|
|
8110
|
-
const BITFLAG_LEVEL = 0x06;
|
|
8111
|
-
const BITFLAG_DATA_DESCRIPTOR = 0x0008;
|
|
8112
|
-
const BITFLAG_LANG_ENCODING_FLAG = 0x0800;
|
|
8113
|
-
const FILE_ATTR_MSDOS_DIR_MASK = 0x10;
|
|
8114
|
-
|
|
8115
|
-
const VERSION_DEFLATE = 0x14;
|
|
8116
|
-
const VERSION_ZIP64 = 0x2D;
|
|
8117
|
-
const VERSION_AES = 0x33;
|
|
8118
|
-
|
|
8119
|
-
const DIRECTORY_SIGNATURE = "/";
|
|
8120
|
-
|
|
8121
|
-
const MAX_DATE = new Date(2107, 11, 31);
|
|
8122
|
-
const MIN_DATE = new Date(1980, 0, 1);
|
|
8123
|
-
|
|
8124
8161
|
/*
|
|
8125
8162
|
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
8126
8163
|
|
|
@@ -8325,7 +8362,7 @@ class ZipReader {
|
|
|
8325
8362
|
let { reader } = zipReader;
|
|
8326
8363
|
const { config } = zipReader;
|
|
8327
8364
|
await initStream(reader);
|
|
8328
|
-
if (reader.size ===
|
|
8365
|
+
if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
|
|
8329
8366
|
if (Array.isArray(reader)) {
|
|
8330
8367
|
reader = new SplitZipReader(reader);
|
|
8331
8368
|
} else {
|
|
@@ -8355,7 +8392,7 @@ class ZipReader {
|
|
|
8355
8392
|
const commentLength = getUint16(endOfDirectoryView, 20);
|
|
8356
8393
|
const appendedDataOffset = commentOffset + END_OF_CENTRAL_DIR_LENGTH + commentLength;
|
|
8357
8394
|
let diskNumber = getUint16(endOfDirectoryView, 4);
|
|
8358
|
-
if (lastDiskNumber !==
|
|
8395
|
+
if (lastDiskNumber !== UNDEFINED_VALUE && diskNumber != lastDiskNumber) {
|
|
8359
8396
|
throw new Error(ERR_SPLIT_ZIP_FILE);
|
|
8360
8397
|
}
|
|
8361
8398
|
let filesLength = getUint16(endOfDirectoryView, 8);
|
|
@@ -8540,8 +8577,9 @@ class ZipEntry$1 {
|
|
|
8540
8577
|
throw new Error(ERR_LOCAL_FILE_HEADER_NOT_FOUND);
|
|
8541
8578
|
}
|
|
8542
8579
|
readCommonHeader(localDirectory, dataView, 4);
|
|
8543
|
-
|
|
8544
|
-
|
|
8580
|
+
localDirectory.rawExtraField = localDirectory.extraFieldLength ?
|
|
8581
|
+
await readUint8Array(reader, offset + 30 + localDirectory.filenameLength, localDirectory.extraFieldLength, diskNumberStart) :
|
|
8582
|
+
new Uint8Array();
|
|
8545
8583
|
await readCommonFooter(zipEntry, localDirectory, dataView, 4);
|
|
8546
8584
|
Object.assign(fileEntry, {
|
|
8547
8585
|
lastAccessDate: localDirectory.lastAccessDate,
|
|
@@ -8550,7 +8588,7 @@ class ZipEntry$1 {
|
|
|
8550
8588
|
const encrypted = zipEntry.encrypted && localDirectory.encrypted;
|
|
8551
8589
|
const zipCrypto = encrypted && !extraFieldAES;
|
|
8552
8590
|
if (encrypted) {
|
|
8553
|
-
if (!zipCrypto && extraFieldAES.strength ===
|
|
8591
|
+
if (!zipCrypto && extraFieldAES.strength === UNDEFINED_VALUE) {
|
|
8554
8592
|
throw new Error(ERR_UNSUPPORTED_ENCRYPTION);
|
|
8555
8593
|
} else if (!password) {
|
|
8556
8594
|
throw new Error(ERR_ENCRYPTED);
|
|
@@ -8567,7 +8605,7 @@ class ZipEntry$1 {
|
|
|
8567
8605
|
};
|
|
8568
8606
|
}
|
|
8569
8607
|
const { writable } = writer;
|
|
8570
|
-
if (writable.size ===
|
|
8608
|
+
if (writable.size === UNDEFINED_VALUE) {
|
|
8571
8609
|
writable.size = 0;
|
|
8572
8610
|
}
|
|
8573
8611
|
const signal = getOptionValue$1(zipEntry, options, "signal");
|
|
@@ -8815,7 +8853,7 @@ async function seekSignature(reader, signature, startOffset, minimumBytes, maxim
|
|
|
8815
8853
|
}
|
|
8816
8854
|
|
|
8817
8855
|
function getOptionValue$1(zipReader, options, name) {
|
|
8818
|
-
return options[name] ===
|
|
8856
|
+
return options[name] === UNDEFINED_VALUE ? zipReader.options[name] : options[name];
|
|
8819
8857
|
}
|
|
8820
8858
|
|
|
8821
8859
|
function getDate(timeRaw) {
|
|
@@ -8905,7 +8943,7 @@ class ZipWriter {
|
|
|
8905
8943
|
if (writer instanceof WritableStream) {
|
|
8906
8944
|
writer = { writable: writer };
|
|
8907
8945
|
}
|
|
8908
|
-
if (writer.writable.size ===
|
|
8946
|
+
if (writer.writable.size === UNDEFINED_VALUE) {
|
|
8909
8947
|
writer.writable.size = 0;
|
|
8910
8948
|
}
|
|
8911
8949
|
Object.assign(this, {
|
|
@@ -8999,7 +9037,7 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
8999
9037
|
const password = getOptionValue(zipWriter, options, "password");
|
|
9000
9038
|
const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength") || 3;
|
|
9001
9039
|
const zipCrypto = getOptionValue(zipWriter, options, "zipCrypto");
|
|
9002
|
-
if (password !==
|
|
9040
|
+
if (password !== UNDEFINED_VALUE && encryptionStrength !== UNDEFINED_VALUE && (encryptionStrength < 1 || encryptionStrength > 3)) {
|
|
9003
9041
|
throw new Error(ERR_INVALID_ENCRYPTION_STRENGTH);
|
|
9004
9042
|
}
|
|
9005
9043
|
let rawExtraField = new Uint8Array();
|
|
@@ -9023,18 +9061,18 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
9023
9061
|
});
|
|
9024
9062
|
}
|
|
9025
9063
|
let extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp");
|
|
9026
|
-
if (extendedTimestamp ===
|
|
9064
|
+
if (extendedTimestamp === UNDEFINED_VALUE) {
|
|
9027
9065
|
extendedTimestamp = true;
|
|
9028
9066
|
}
|
|
9029
9067
|
let maximumCompressedSize = 0;
|
|
9030
9068
|
let maximumEntrySize = 0;
|
|
9031
9069
|
let keepOrder = getOptionValue(zipWriter, options, "keepOrder");
|
|
9032
|
-
if (keepOrder ===
|
|
9070
|
+
if (keepOrder === UNDEFINED_VALUE) {
|
|
9033
9071
|
keepOrder = true;
|
|
9034
9072
|
}
|
|
9035
9073
|
let uncompressedSize = 0;
|
|
9036
9074
|
let msDosCompatible = getOptionValue(zipWriter, options, "msDosCompatible");
|
|
9037
|
-
if (msDosCompatible ===
|
|
9075
|
+
if (msDosCompatible === UNDEFINED_VALUE) {
|
|
9038
9076
|
msDosCompatible = true;
|
|
9039
9077
|
}
|
|
9040
9078
|
const internalFileAttribute = getOptionValue(zipWriter, options, "internalFileAttribute") || 0;
|
|
@@ -9047,15 +9085,16 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
9047
9085
|
};
|
|
9048
9086
|
}
|
|
9049
9087
|
await initStream(reader);
|
|
9050
|
-
if (reader.size ===
|
|
9088
|
+
if (reader.size === UNDEFINED_VALUE) {
|
|
9051
9089
|
options.dataDescriptor = true;
|
|
9052
|
-
if (zip64 ===
|
|
9090
|
+
if (zip64 || zip64 === UNDEFINED_VALUE) {
|
|
9053
9091
|
zip64 = true;
|
|
9092
|
+
maximumCompressedSize = MAX_32_BITS;
|
|
9054
9093
|
}
|
|
9055
9094
|
} else {
|
|
9056
9095
|
uncompressedSize = reader.size;
|
|
9096
|
+
maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
|
|
9057
9097
|
}
|
|
9058
|
-
maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
|
|
9059
9098
|
}
|
|
9060
9099
|
if (zipWriter.offset + zipWriter.pendingEntriesSize >= MAX_32_BITS ||
|
|
9061
9100
|
uncompressedSize >= MAX_32_BITS ||
|
|
@@ -9074,10 +9113,10 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
9074
9113
|
let dataDescriptorSignature = getOptionValue(zipWriter, options, "dataDescriptorSignature");
|
|
9075
9114
|
const signal = getOptionValue(zipWriter, options, "signal");
|
|
9076
9115
|
const useCompressionStream = getOptionValue(zipWriter, options, "useCompressionStream");
|
|
9077
|
-
if (dataDescriptor ===
|
|
9116
|
+
if (dataDescriptor === UNDEFINED_VALUE) {
|
|
9078
9117
|
dataDescriptor = true;
|
|
9079
9118
|
}
|
|
9080
|
-
if (dataDescriptor && dataDescriptorSignature ===
|
|
9119
|
+
if (dataDescriptor && dataDescriptorSignature === UNDEFINED_VALUE) {
|
|
9081
9120
|
dataDescriptorSignature = false;
|
|
9082
9121
|
}
|
|
9083
9122
|
options = Object.assign({}, options, {
|
|
@@ -9544,7 +9583,7 @@ function setEntryInfo(entryInfo, options) {
|
|
|
9544
9583
|
zipCrypto,
|
|
9545
9584
|
dataDescriptor
|
|
9546
9585
|
} = options;
|
|
9547
|
-
if ((!encrypted || zipCrypto) && signature !==
|
|
9586
|
+
if ((!encrypted || zipCrypto) && signature !== UNDEFINED_VALUE) {
|
|
9548
9587
|
setUint32(headerView, 10, signature);
|
|
9549
9588
|
if (dataDescriptor) {
|
|
9550
9589
|
setUint32(dataDescriptorView, dataDescriptorOffset, signature);
|
|
@@ -9731,7 +9770,7 @@ function getTimeNTFS(date) {
|
|
|
9731
9770
|
}
|
|
9732
9771
|
|
|
9733
9772
|
function getOptionValue(zipWriter, options, name) {
|
|
9734
|
-
return options[name] ===
|
|
9773
|
+
return options[name] === UNDEFINED_VALUE ? zipWriter.options[name] : options[name];
|
|
9735
9774
|
}
|
|
9736
9775
|
|
|
9737
9776
|
function getMaximumCompressedSize(uncompressedSize) {
|
package/index.d.ts
CHANGED
|
@@ -273,7 +273,6 @@ export function getMimeType(fileExtension: string): string
|
|
|
273
273
|
interface DataProcessor {
|
|
274
274
|
/**
|
|
275
275
|
* Initializes the instance asynchronously
|
|
276
|
-
*
|
|
277
276
|
*/
|
|
278
277
|
init?(): Promise<void>
|
|
279
278
|
}
|
|
@@ -295,17 +294,17 @@ interface ReadableReader {
|
|
|
295
294
|
* Here is an example of custom `Reader` class used to read binary strings:
|
|
296
295
|
* ```
|
|
297
296
|
* class BinaryStringReader extends Reader {
|
|
298
|
-
*
|
|
297
|
+
*
|
|
299
298
|
* constructor(binaryString) {
|
|
300
299
|
* super();
|
|
301
300
|
* this.binaryString = binaryString;
|
|
302
301
|
* }
|
|
303
|
-
*
|
|
302
|
+
*
|
|
304
303
|
* init() {
|
|
305
304
|
* super.init();
|
|
306
305
|
* this.size = this.binaryString.length;
|
|
307
306
|
* }
|
|
308
|
-
*
|
|
307
|
+
*
|
|
309
308
|
* readUint8Array(offset, length) {
|
|
310
309
|
* const result = new Uint8Array(length);
|
|
311
310
|
* for (let indexCharacter = 0; indexCharacter < length; indexCharacter++) {
|
|
@@ -333,7 +332,6 @@ export class Reader<Type> implements ReadableReader, DataProcessor {
|
|
|
333
332
|
size: number
|
|
334
333
|
/**
|
|
335
334
|
* Initializes the instance asynchronously
|
|
336
|
-
*
|
|
337
335
|
*/
|
|
338
336
|
init?(): Promise<void>
|
|
339
337
|
/**
|