@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.
@@ -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 MINIMUM_CHUNK_SIZE = 64;
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 != "undefined" && navigator.hardwareConcurrency) {
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: undefined,
5992
- CompressionStreamNative: typeof CompressionStream != "undefined" && CompressionStream,
5993
- DecompressionStreamNative: typeof DecompressionStream != "undefined" && 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);
@@ -7167,8 +7239,8 @@
7167
7239
  }
7168
7240
  };
7169
7241
  workerData.readable = readable.pipeThrough(new TransformStream(transformer, { highWaterMark: 1, size: () => config.chunkSize }), { signal });
7170
- if (workersSupported === undefined) {
7171
- workersSupported = typeof Worker != "undefined";
7242
+ if (workersSupported === UNDEFINED_VALUE) {
7243
+ workersSupported = typeof Worker != UNDEFINED_TYPE;
7172
7244
  }
7173
7245
  return useWebWorkers && workersSupported ? createWebWorkerInterface(workerData, config) : createWorkerInterface(workerData, config);
7174
7246
  }
@@ -7227,7 +7299,7 @@
7227
7299
  const writable = new WritableStream({
7228
7300
  async write(chunk) {
7229
7301
  await writer.ready;
7230
- await writer.write(new Uint8Array(chunk));
7302
+ await writer.write(chunk);
7231
7303
  },
7232
7304
  async close() {
7233
7305
  writer.releaseLock();
@@ -7403,11 +7475,11 @@
7403
7475
  const { options, config } = workerOptions;
7404
7476
  const { transferStreams, useWebWorkers, useCompressionStream, codecType, compressed, signed, encrypted } = options;
7405
7477
  const { workerScripts } = config;
7406
- workerOptions.transferStreams = transferStreams || transferStreams === undefined;
7478
+ workerOptions.transferStreams = transferStreams || transferStreams === UNDEFINED_VALUE;
7407
7479
  const streamCopy = !compressed && !signed && !encrypted && !workerOptions.transferStreams;
7408
- workerOptions.useWebWorkers = !streamCopy && (useWebWorkers || (useWebWorkers === undefined && config.useWebWorkers));
7480
+ workerOptions.useWebWorkers = !streamCopy && (useWebWorkers || (useWebWorkers === UNDEFINED_VALUE && config.useWebWorkers));
7409
7481
  workerOptions.scripts = workerOptions.useWebWorkers && workerScripts ? workerScripts[codecType] : [];
7410
- options.useCompressionStream = useCompressionStream || (useCompressionStream === undefined && config.useCompressionStream);
7482
+ options.useCompressionStream = useCompressionStream || (useCompressionStream === UNDEFINED_VALUE && config.useCompressionStream);
7411
7483
  let worker;
7412
7484
  if (pool.length < config.maxWorkers) {
7413
7485
  const workerData = { indexWorker };
@@ -7548,11 +7620,14 @@
7548
7620
  const HTTP_HEADER_CONTENT_RANGE = "Content-Range";
7549
7621
  const HTTP_HEADER_ACCEPT_RANGES = "Accept-Ranges";
7550
7622
  const HTTP_HEADER_RANGE = "Range";
7623
+ const HTTP_HEADER_CONTENT_TYPE = "Content-Type";
7551
7624
  const HTTP_METHOD_HEAD = "HEAD";
7552
7625
  const HTTP_METHOD_GET = "GET";
7553
7626
  const HTTP_RANGE_UNIT = "bytes";
7554
7627
  const DEFAULT_CHUNK_SIZE = 64 * 1024;
7555
7628
 
7629
+ const PROPERTY_NAME_WRITABLE = "writable";
7630
+
7556
7631
  class Stream {
7557
7632
 
7558
7633
  constructor() {
@@ -7598,7 +7673,7 @@
7598
7673
  return writer.writeUint8Array(chunk);
7599
7674
  }
7600
7675
  });
7601
- Object.defineProperty(writer, "writable", {
7676
+ Object.defineProperty(writer, PROPERTY_NAME_WRITABLE, {
7602
7677
  get() {
7603
7678
  return writable;
7604
7679
  }
@@ -7614,21 +7689,26 @@
7614
7689
 
7615
7690
  constructor(dataURI) {
7616
7691
  super();
7617
- const reader = this;
7618
- reader.dataURI = dataURI;
7619
7692
  let dataEnd = dataURI.length;
7620
7693
  while (dataURI.charAt(dataEnd - 1) == "=") {
7621
7694
  dataEnd--;
7622
7695
  }
7623
- reader.dataStart = dataURI.indexOf(",") + 1;
7624
- reader.size = Math.floor((dataEnd - reader.dataStart) * 0.75);
7696
+ const dataStart = dataURI.indexOf(",") + 1;
7697
+ Object.assign(this, {
7698
+ dataURI,
7699
+ dataStart,
7700
+ size: Math.floor((dataEnd - dataStart) * 0.75)
7701
+ });
7625
7702
  }
7626
7703
 
7627
7704
  readUint8Array(offset, length) {
7705
+ const {
7706
+ dataStart,
7707
+ dataURI
7708
+ } = this;
7628
7709
  const dataArray = new Uint8Array(length);
7629
7710
  const start = Math.floor(offset / 3) * 4;
7630
- const dataStart = this.dataStart;
7631
- const bytes = atob(this.dataURI.substring(start + dataStart, Math.ceil((offset + length) / 3) * 4 + dataStart));
7711
+ const bytes = atob(dataURI.substring(start + dataStart, Math.ceil((offset + length) / 3) * 4 + dataStart));
7632
7712
  const delta = offset - Math.floor(start / 4) * 3;
7633
7713
  for (let indexByte = delta; indexByte < delta + length; indexByte++) {
7634
7714
  dataArray[indexByte - delta] = bytes.charCodeAt(indexByte);
@@ -7641,8 +7721,10 @@
7641
7721
 
7642
7722
  constructor(contentType) {
7643
7723
  super();
7644
- this.data = "data:" + (contentType || "") + ";base64,";
7645
- this.pending = [];
7724
+ Object.assign(this, {
7725
+ data: "data:" + (contentType || "") + ";base64,",
7726
+ pending: []
7727
+ });
7646
7728
  }
7647
7729
 
7648
7730
  writeUint8Array(array) {
@@ -7673,8 +7755,10 @@
7673
7755
 
7674
7756
  constructor(blob) {
7675
7757
  super();
7676
- this.blob = blob;
7677
- this.size = blob.size;
7758
+ Object.assign(this, {
7759
+ blob,
7760
+ size: blob.size
7761
+ });
7678
7762
  }
7679
7763
 
7680
7764
  async readUint8Array(offset, length) {
@@ -7691,9 +7775,9 @@
7691
7775
  const transformStream = new TransformStream();
7692
7776
  const headers = [];
7693
7777
  if (contentType) {
7694
- headers.push(["content-type", contentType]);
7778
+ headers.push([HTTP_HEADER_CONTENT_TYPE, contentType]);
7695
7779
  }
7696
- Object.defineProperty(writer, "writable", {
7780
+ Object.defineProperty(writer, PROPERTY_NAME_WRITABLE, {
7697
7781
  get() {
7698
7782
  return transformStream.writable;
7699
7783
  }
@@ -7734,8 +7818,10 @@
7734
7818
  } else {
7735
7819
  const reader = new FileReader();
7736
7820
  return new Promise((resolve, reject) => {
7737
- reader.onload = ({ target }) => resolve(target.result);
7738
- reader.onerror = () => reject(reader.error);
7821
+ Object.assign(reader, {
7822
+ onload: ({ target }) => resolve(target.result),
7823
+ onerror: () => reject(reader.error)
7824
+ });
7739
7825
  reader.readAsText(blob, encoding);
7740
7826
  });
7741
7827
  }
@@ -7746,16 +7832,7 @@
7746
7832
 
7747
7833
  constructor(url, options) {
7748
7834
  super();
7749
- const reader = this;
7750
- reader.url = url;
7751
- reader.preventHeadRequest = options.preventHeadRequest;
7752
- reader.useRangeHeader = options.useRangeHeader;
7753
- reader.forceRangeRequests = options.forceRangeRequests;
7754
- reader.options = options = Object.assign({}, options);
7755
- delete options.preventHeadRequest;
7756
- delete options.useRangeHeader;
7757
- delete options.forceRangeRequests;
7758
- delete options.useXHR;
7835
+ createHtpReader(this, url, options);
7759
7836
  }
7760
7837
 
7761
7838
  async init() {
@@ -7772,12 +7849,7 @@
7772
7849
 
7773
7850
  constructor(url, options) {
7774
7851
  super();
7775
- const reader = this;
7776
- reader.url = url;
7777
- reader.preventHeadRequest = options.preventHeadRequest;
7778
- reader.useRangeHeader = options.useRangeHeader;
7779
- reader.forceRangeRequests = options.forceRangeRequests;
7780
- reader.options = options;
7852
+ createHtpReader(this, url, options);
7781
7853
  }
7782
7854
 
7783
7855
  async init() {
@@ -7790,14 +7862,39 @@
7790
7862
  }
7791
7863
  }
7792
7864
 
7865
+ function createHtpReader(httpReader, url, options) {
7866
+ const {
7867
+ preventHeadRequest,
7868
+ useRangeHeader,
7869
+ forceRangeRequests
7870
+ } = options;
7871
+ options = Object.assign({}, options);
7872
+ delete options.preventHeadRequest;
7873
+ delete options.useRangeHeader;
7874
+ delete options.forceRangeRequests;
7875
+ delete options.useXHR;
7876
+ Object.assign(httpReader, {
7877
+ url,
7878
+ options,
7879
+ preventHeadRequest,
7880
+ useRangeHeader,
7881
+ forceRangeRequests
7882
+ });
7883
+ }
7884
+
7793
7885
  async function initHttpReader(httpReader, sendRequest, getRequestData) {
7794
- if (isHttpFamily(httpReader.url) && (httpReader.useRangeHeader || httpReader.forceRangeRequests)) {
7795
- const response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader));
7796
- if (!httpReader.forceRangeRequests && response.headers.get(HTTP_HEADER_ACCEPT_RANGES) != HTTP_RANGE_UNIT) {
7886
+ const {
7887
+ url,
7888
+ useRangeHeader,
7889
+ forceRangeRequests
7890
+ } = httpReader;
7891
+ if (isHttpFamily(url) && (useRangeHeader || forceRangeRequests)) {
7892
+ const { headers } = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader));
7893
+ if (!forceRangeRequests && headers.get(HTTP_HEADER_ACCEPT_RANGES) != HTTP_RANGE_UNIT) {
7797
7894
  throw new Error(ERR_HTTP_RANGE);
7798
7895
  } else {
7799
7896
  let contentSize;
7800
- const contentRangeHeader = response.headers.get(HTTP_HEADER_CONTENT_RANGE);
7897
+ const contentRangeHeader = headers.get(HTTP_HEADER_CONTENT_RANGE);
7801
7898
  if (contentRangeHeader) {
7802
7899
  const splitHeader = contentRangeHeader.trim().split(/\s*\/\s*/);
7803
7900
  if (splitHeader.length) {
@@ -7807,7 +7904,7 @@
7807
7904
  }
7808
7905
  }
7809
7906
  }
7810
- if (contentSize === undefined) {
7907
+ if (contentSize === UNDEFINED_VALUE) {
7811
7908
  await getContentLength(httpReader, sendRequest, getRequestData);
7812
7909
  } else {
7813
7910
  httpReader.size = contentSize;
@@ -7819,17 +7916,23 @@
7819
7916
  }
7820
7917
 
7821
7918
  async function readUint8ArrayHttpReader(httpReader, index, length, sendRequest, getRequestData) {
7822
- if (httpReader.useRangeHeader || httpReader.forceRangeRequests) {
7919
+ const {
7920
+ data,
7921
+ useRangeHeader,
7922
+ forceRangeRequests,
7923
+ options
7924
+ } = httpReader;
7925
+ if (useRangeHeader || forceRangeRequests) {
7823
7926
  const response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader, index, length));
7824
7927
  if (response.status != 206) {
7825
7928
  throw new Error(ERR_HTTP_RANGE);
7826
7929
  }
7827
7930
  return new Uint8Array(await response.arrayBuffer());
7828
7931
  } else {
7829
- if (!httpReader.data) {
7830
- await getRequestData(httpReader, httpReader.options);
7932
+ if (!data) {
7933
+ await getRequestData(httpReader, options);
7831
7934
  }
7832
- return new Uint8Array(httpReader.data.subarray(index, index + length));
7935
+ return new Uint8Array(data.subarray(index, index + length));
7833
7936
  }
7834
7937
  }
7835
7938
 
@@ -7837,8 +7940,8 @@
7837
7940
  return Object.assign({}, getHeaders(httpReader), { [HTTP_HEADER_RANGE]: HTTP_RANGE_UNIT + "=" + index + "-" + (index + length - 1) });
7838
7941
  }
7839
7942
 
7840
- function getHeaders(httpReader) {
7841
- const headers = httpReader.options.headers;
7943
+ function getHeaders({ options }) {
7944
+ const { headers } = options;
7842
7945
  if (headers) {
7843
7946
  if (Symbol.iterator in headers) {
7844
7947
  return Object.fromEntries(headers);
@@ -7923,9 +8026,10 @@
7923
8026
 
7924
8027
  constructor(url, options = {}) {
7925
8028
  super();
7926
- const reader = this;
7927
- reader.url = url;
7928
- reader.reader = options.useXHR ? new XHRReader(url, options) : new FetchReader(url, options);
8029
+ Object.assign(this, {
8030
+ url,
8031
+ reader: options.useXHR ? new XHRReader(url, options) : new FetchReader(url, options)
8032
+ });
7929
8033
  }
7930
8034
 
7931
8035
  set size(value) {
@@ -7959,8 +8063,10 @@
7959
8063
 
7960
8064
  constructor(array) {
7961
8065
  super();
7962
- this.array = array;
7963
- this.size = array.length;
8066
+ Object.assign(this, {
8067
+ array,
8068
+ size: array.length
8069
+ });
7964
8070
  }
7965
8071
 
7966
8072
  readUint8Array(index, length) {
@@ -7972,9 +8078,10 @@
7972
8078
 
7973
8079
  init(initSize = 0) {
7974
8080
  super.init();
7975
- const writer = this;
7976
- writer.offset = 0;
7977
- writer.array = new Uint8Array(initSize);
8081
+ Object.assign(this, {
8082
+ offset: 0,
8083
+ array: new Uint8Array(initSize)
8084
+ });
7978
8085
  }
7979
8086
 
7980
8087
  writeUint8Array(array) {
@@ -8055,76 +8162,6 @@
8055
8162
  return reader.readUint8Array(offset, size, diskNumber);
8056
8163
  }
8057
8164
 
8058
- /*
8059
- Copyright (c) 2022 Gildas Lormeau. All rights reserved.
8060
-
8061
- Redistribution and use in source and binary forms, with or without
8062
- modification, are permitted provided that the following conditions are met:
8063
-
8064
- 1. Redistributions of source code must retain the above copyright notice,
8065
- this list of conditions and the following disclaimer.
8066
-
8067
- 2. Redistributions in binary form must reproduce the above copyright
8068
- notice, this list of conditions and the following disclaimer in
8069
- the documentation and/or other materials provided with the distribution.
8070
-
8071
- 3. The names of the authors may not be used to endorse or promote products
8072
- derived from this software without specific prior written permission.
8073
-
8074
- THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
8075
- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
8076
- FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
8077
- INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
8078
- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
8079
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
8080
- OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
8081
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
8082
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
8083
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8084
- */
8085
-
8086
- const MAX_32_BITS = 0xffffffff;
8087
- const MAX_16_BITS = 0xffff;
8088
- const COMPRESSION_METHOD_DEFLATE = 0x08;
8089
- const COMPRESSION_METHOD_STORE = 0x00;
8090
- const COMPRESSION_METHOD_AES = 0x63;
8091
-
8092
- const LOCAL_FILE_HEADER_SIGNATURE = 0x04034b50;
8093
- const DATA_DESCRIPTOR_RECORD_SIGNATURE = 0x08074b50;
8094
- const CENTRAL_FILE_HEADER_SIGNATURE = 0x02014b50;
8095
- const END_OF_CENTRAL_DIR_SIGNATURE = 0x06054b50;
8096
- const ZIP64_END_OF_CENTRAL_DIR_SIGNATURE = 0x06064b50;
8097
- const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE = 0x07064b50;
8098
- const END_OF_CENTRAL_DIR_LENGTH = 22;
8099
- const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH = 20;
8100
- const ZIP64_END_OF_CENTRAL_DIR_LENGTH = 56;
8101
- 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;
8102
-
8103
- const ZIP64_TOTAL_NUMBER_OF_DISKS = 1;
8104
-
8105
- const EXTRAFIELD_TYPE_ZIP64 = 0x0001;
8106
- const EXTRAFIELD_TYPE_AES = 0x9901;
8107
- const EXTRAFIELD_TYPE_NTFS = 0x000a;
8108
- const EXTRAFIELD_TYPE_NTFS_TAG1 = 0x0001;
8109
- const EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP = 0x5455;
8110
- const EXTRAFIELD_TYPE_UNICODE_PATH = 0x7075;
8111
- const EXTRAFIELD_TYPE_UNICODE_COMMENT = 0x6375;
8112
-
8113
- const BITFLAG_ENCRYPTED = 0x01;
8114
- const BITFLAG_LEVEL = 0x06;
8115
- const BITFLAG_DATA_DESCRIPTOR = 0x0008;
8116
- const BITFLAG_LANG_ENCODING_FLAG = 0x0800;
8117
- const FILE_ATTR_MSDOS_DIR_MASK = 0x10;
8118
-
8119
- const VERSION_DEFLATE = 0x14;
8120
- const VERSION_ZIP64 = 0x2D;
8121
- const VERSION_AES = 0x33;
8122
-
8123
- const DIRECTORY_SIGNATURE = "/";
8124
-
8125
- const MAX_DATE = new Date(2107, 11, 31);
8126
- const MIN_DATE = new Date(1980, 0, 1);
8127
-
8128
8165
  /*
8129
8166
  Copyright (c) 2022 Gildas Lormeau. All rights reserved.
8130
8167
 
@@ -8329,7 +8366,7 @@
8329
8366
  let { reader } = zipReader;
8330
8367
  const { config } = zipReader;
8331
8368
  await initStream(reader);
8332
- if (reader.size === undefined || !reader.readUint8Array) {
8369
+ if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
8333
8370
  if (Array.isArray(reader)) {
8334
8371
  reader = new SplitZipReader(reader);
8335
8372
  } else {
@@ -8359,7 +8396,7 @@
8359
8396
  const commentLength = getUint16(endOfDirectoryView, 20);
8360
8397
  const appendedDataOffset = commentOffset + END_OF_CENTRAL_DIR_LENGTH + commentLength;
8361
8398
  let diskNumber = getUint16(endOfDirectoryView, 4);
8362
- if (lastDiskNumber !== undefined && diskNumber != lastDiskNumber) {
8399
+ if (lastDiskNumber !== UNDEFINED_VALUE && diskNumber != lastDiskNumber) {
8363
8400
  throw new Error(ERR_SPLIT_ZIP_FILE);
8364
8401
  }
8365
8402
  let filesLength = getUint16(endOfDirectoryView, 8);
@@ -8544,8 +8581,9 @@
8544
8581
  throw new Error(ERR_LOCAL_FILE_HEADER_NOT_FOUND);
8545
8582
  }
8546
8583
  readCommonHeader(localDirectory, dataView, 4);
8547
- dataArray = await readUint8Array(reader, offset, 30 + localDirectory.filenameLength + localDirectory.extraFieldLength, diskNumberStart);
8548
- localDirectory.rawExtraField = dataArray.subarray(30 + localDirectory.filenameLength);
8584
+ localDirectory.rawExtraField = localDirectory.extraFieldLength ?
8585
+ await readUint8Array(reader, offset + 30 + localDirectory.filenameLength, localDirectory.extraFieldLength, diskNumberStart) :
8586
+ new Uint8Array();
8549
8587
  await readCommonFooter(zipEntry, localDirectory, dataView, 4);
8550
8588
  Object.assign(fileEntry, {
8551
8589
  lastAccessDate: localDirectory.lastAccessDate,
@@ -8554,7 +8592,7 @@
8554
8592
  const encrypted = zipEntry.encrypted && localDirectory.encrypted;
8555
8593
  const zipCrypto = encrypted && !extraFieldAES;
8556
8594
  if (encrypted) {
8557
- if (!zipCrypto && extraFieldAES.strength === undefined) {
8595
+ if (!zipCrypto && extraFieldAES.strength === UNDEFINED_VALUE) {
8558
8596
  throw new Error(ERR_UNSUPPORTED_ENCRYPTION);
8559
8597
  } else if (!password) {
8560
8598
  throw new Error(ERR_ENCRYPTED);
@@ -8571,7 +8609,7 @@
8571
8609
  };
8572
8610
  }
8573
8611
  const { writable } = writer;
8574
- if (writable.size === undefined) {
8612
+ if (writable.size === UNDEFINED_VALUE) {
8575
8613
  writable.size = 0;
8576
8614
  }
8577
8615
  const signal = getOptionValue$1(zipEntry, options, "signal");
@@ -8819,7 +8857,7 @@
8819
8857
  }
8820
8858
 
8821
8859
  function getOptionValue$1(zipReader, options, name) {
8822
- return options[name] === undefined ? zipReader.options[name] : options[name];
8860
+ return options[name] === UNDEFINED_VALUE ? zipReader.options[name] : options[name];
8823
8861
  }
8824
8862
 
8825
8863
  function getDate(timeRaw) {
@@ -8909,7 +8947,7 @@
8909
8947
  if (writer instanceof WritableStream) {
8910
8948
  writer = { writable: writer };
8911
8949
  }
8912
- if (writer.writable.size === undefined) {
8950
+ if (writer.writable.size === UNDEFINED_VALUE) {
8913
8951
  writer.writable.size = 0;
8914
8952
  }
8915
8953
  Object.assign(this, {
@@ -9003,7 +9041,7 @@
9003
9041
  const password = getOptionValue(zipWriter, options, "password");
9004
9042
  const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength") || 3;
9005
9043
  const zipCrypto = getOptionValue(zipWriter, options, "zipCrypto");
9006
- if (password !== undefined && encryptionStrength !== undefined && (encryptionStrength < 1 || encryptionStrength > 3)) {
9044
+ if (password !== UNDEFINED_VALUE && encryptionStrength !== UNDEFINED_VALUE && (encryptionStrength < 1 || encryptionStrength > 3)) {
9007
9045
  throw new Error(ERR_INVALID_ENCRYPTION_STRENGTH);
9008
9046
  }
9009
9047
  let rawExtraField = new Uint8Array();
@@ -9027,18 +9065,18 @@
9027
9065
  });
9028
9066
  }
9029
9067
  let extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp");
9030
- if (extendedTimestamp === undefined) {
9068
+ if (extendedTimestamp === UNDEFINED_VALUE) {
9031
9069
  extendedTimestamp = true;
9032
9070
  }
9033
9071
  let maximumCompressedSize = 0;
9034
9072
  let maximumEntrySize = 0;
9035
9073
  let keepOrder = getOptionValue(zipWriter, options, "keepOrder");
9036
- if (keepOrder === undefined) {
9074
+ if (keepOrder === UNDEFINED_VALUE) {
9037
9075
  keepOrder = true;
9038
9076
  }
9039
9077
  let uncompressedSize = 0;
9040
9078
  let msDosCompatible = getOptionValue(zipWriter, options, "msDosCompatible");
9041
- if (msDosCompatible === undefined) {
9079
+ if (msDosCompatible === UNDEFINED_VALUE) {
9042
9080
  msDosCompatible = true;
9043
9081
  }
9044
9082
  const internalFileAttribute = getOptionValue(zipWriter, options, "internalFileAttribute") || 0;
@@ -9051,15 +9089,16 @@
9051
9089
  };
9052
9090
  }
9053
9091
  await initStream(reader);
9054
- if (reader.size === undefined) {
9092
+ if (reader.size === UNDEFINED_VALUE) {
9055
9093
  options.dataDescriptor = true;
9056
- if (zip64 === undefined) {
9094
+ if (zip64 || zip64 === UNDEFINED_VALUE) {
9057
9095
  zip64 = true;
9096
+ maximumCompressedSize = MAX_32_BITS;
9058
9097
  }
9059
9098
  } else {
9060
9099
  uncompressedSize = reader.size;
9100
+ maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
9061
9101
  }
9062
- maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
9063
9102
  }
9064
9103
  if (zipWriter.offset + zipWriter.pendingEntriesSize >= MAX_32_BITS ||
9065
9104
  uncompressedSize >= MAX_32_BITS ||
@@ -9078,10 +9117,10 @@
9078
9117
  let dataDescriptorSignature = getOptionValue(zipWriter, options, "dataDescriptorSignature");
9079
9118
  const signal = getOptionValue(zipWriter, options, "signal");
9080
9119
  const useCompressionStream = getOptionValue(zipWriter, options, "useCompressionStream");
9081
- if (dataDescriptor === undefined) {
9120
+ if (dataDescriptor === UNDEFINED_VALUE) {
9082
9121
  dataDescriptor = true;
9083
9122
  }
9084
- if (dataDescriptor && dataDescriptorSignature === undefined) {
9123
+ if (dataDescriptor && dataDescriptorSignature === UNDEFINED_VALUE) {
9085
9124
  dataDescriptorSignature = false;
9086
9125
  }
9087
9126
  options = Object.assign({}, options, {
@@ -9548,7 +9587,7 @@
9548
9587
  zipCrypto,
9549
9588
  dataDescriptor
9550
9589
  } = options;
9551
- if ((!encrypted || zipCrypto) && signature !== undefined) {
9590
+ if ((!encrypted || zipCrypto) && signature !== UNDEFINED_VALUE) {
9552
9591
  setUint32(headerView, 10, signature);
9553
9592
  if (dataDescriptor) {
9554
9593
  setUint32(dataDescriptorView, dataDescriptorOffset, signature);
@@ -9735,7 +9774,7 @@
9735
9774
  }
9736
9775
 
9737
9776
  function getOptionValue(zipWriter, options, name) {
9738
- return options[name] === undefined ? zipWriter.options[name] : options[name];
9777
+ return options[name] === UNDEFINED_VALUE ? zipWriter.options[name] : options[name];
9739
9778
  }
9740
9779
 
9741
9780
  function getMaximumCompressedSize(uncompressedSize) {