@zip.js/zip.js 2.7.40 → 2.7.42

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-full.js CHANGED
@@ -7002,35 +7002,43 @@
7002
7002
  const {
7003
7003
  preventHeadRequest,
7004
7004
  useRangeHeader,
7005
- forceRangeRequests
7005
+ forceRangeRequests,
7006
+ combineSizeEocd
7006
7007
  } = options;
7007
7008
  options = Object.assign({}, options);
7008
7009
  delete options.preventHeadRequest;
7009
7010
  delete options.useRangeHeader;
7010
7011
  delete options.forceRangeRequests;
7012
+ delete options.combineSizeEocd;
7011
7013
  delete options.useXHR;
7012
7014
  Object.assign(httpReader, {
7013
7015
  url,
7014
7016
  options,
7015
7017
  preventHeadRequest,
7016
7018
  useRangeHeader,
7017
- forceRangeRequests
7019
+ forceRangeRequests,
7020
+ combineSizeEocd
7018
7021
  });
7019
7022
  }
7020
7023
 
7021
7024
  async function initHttpReader(httpReader, sendRequest, getRequestData) {
7022
7025
  const {
7023
7026
  url,
7027
+ preventHeadRequest,
7024
7028
  useRangeHeader,
7025
- forceRangeRequests
7029
+ forceRangeRequests,
7030
+ combineSizeEocd
7026
7031
  } = httpReader;
7027
- if (isHttpFamily(url) && (useRangeHeader || forceRangeRequests)) {
7028
- const { headers } = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader));
7029
- if (!forceRangeRequests && headers.get(HTTP_HEADER_ACCEPT_RANGES) != HTTP_RANGE_UNIT) {
7032
+ if (isHttpFamily(url) && (useRangeHeader || forceRangeRequests) && (typeof preventHeadRequest == "undefined" || preventHeadRequest)) {
7033
+ const response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader, combineSizeEocd ? -END_OF_CENTRAL_DIR_LENGTH : undefined));
7034
+ if (!forceRangeRequests && response.headers.get(HTTP_HEADER_ACCEPT_RANGES) != HTTP_RANGE_UNIT) {
7030
7035
  throw new Error(ERR_HTTP_RANGE);
7031
7036
  } else {
7037
+ if (combineSizeEocd) {
7038
+ httpReader.eocdCache = new Uint8Array(await response.arrayBuffer());
7039
+ }
7032
7040
  let contentSize;
7033
- const contentRangeHeader = headers.get(HTTP_HEADER_CONTENT_RANGE);
7041
+ const contentRangeHeader = response.headers.get(HTTP_HEADER_CONTENT_RANGE);
7034
7042
  if (contentRangeHeader) {
7035
7043
  const splitHeader = contentRangeHeader.trim().split(/\s*\/\s*/);
7036
7044
  if (splitHeader.length) {
@@ -7055,9 +7063,14 @@
7055
7063
  const {
7056
7064
  useRangeHeader,
7057
7065
  forceRangeRequests,
7066
+ eocdCache,
7067
+ size,
7058
7068
  options
7059
7069
  } = httpReader;
7060
7070
  if (useRangeHeader || forceRangeRequests) {
7071
+ if (eocdCache && index == size - END_OF_CENTRAL_DIR_LENGTH && length == END_OF_CENTRAL_DIR_LENGTH) {
7072
+ return eocdCache;
7073
+ }
7061
7074
  const response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader, index, length));
7062
7075
  if (response.status != 206) {
7063
7076
  throw new Error(ERR_HTTP_RANGE);
@@ -7073,7 +7086,7 @@
7073
7086
  }
7074
7087
 
7075
7088
  function getRangeHeaders(httpReader, index = 0, length = 1) {
7076
- return Object.assign({}, getHeaders(httpReader), { [HTTP_HEADER_RANGE]: HTTP_RANGE_UNIT + "=" + index + "-" + (index + length - 1) });
7089
+ return Object.assign({}, getHeaders(httpReader), { [HTTP_HEADER_RANGE]: HTTP_RANGE_UNIT + "=" + (index < 0 ? index : index + "-" + (index + length - 1)) });
7077
7090
  }
7078
7091
 
7079
7092
  function getHeaders({ options }) {
@@ -7768,9 +7781,10 @@
7768
7781
  commentUTF8,
7769
7782
  rawExtraField: directoryArray.subarray(extraFieldOffset, commentOffset)
7770
7783
  });
7784
+ const decode = getOptionValue$1(zipReader, options, "decodeText") || decodeText;
7771
7785
  const [filename, comment] = await Promise.all([
7772
- decodeText(rawFilename, filenameUTF8 ? CHARSET_UTF8 : filenameEncoding || CHARSET_CP437),
7773
- decodeText(rawComment, commentUTF8 ? CHARSET_UTF8 : commentEncoding || CHARSET_CP437)
7786
+ decode(rawFilename, filenameUTF8 ? CHARSET_UTF8 : filenameEncoding || CHARSET_CP437),
7787
+ decode(rawComment, commentUTF8 ? CHARSET_UTF8 : commentEncoding || CHARSET_CP437)
7774
7788
  ]);
7775
7789
  Object.assign(fileEntry, {
7776
7790
  rawComment,
@@ -8374,12 +8388,13 @@
8374
8388
  } else {
8375
8389
  options.directory = name.endsWith(DIRECTORY_SIGNATURE);
8376
8390
  }
8377
- const rawFilename = encodeText(name);
8391
+ const encode = getOptionValue(zipWriter, options, "encodeText", encodeText);
8392
+ const rawFilename = encode(name);
8378
8393
  if (getLength(rawFilename) > MAX_16_BITS) {
8379
8394
  throw new Error(ERR_INVALID_ENTRY_NAME);
8380
8395
  }
8381
8396
  const comment = options.comment || "";
8382
- const rawComment = encodeText(comment);
8397
+ const rawComment = encode(comment);
8383
8398
  if (getLength(rawComment) > MAX_16_BITS) {
8384
8399
  throw new Error(ERR_INVALID_ENTRY_COMMENT);
8385
8400
  }
@@ -8482,7 +8497,7 @@
8482
8497
  zip64DiskNumberStart,
8483
8498
  password,
8484
8499
  rawPassword,
8485
- level,
8500
+ level: !useCompressionStream && zipWriter.config.CompressionStream === UNDEFINED_VALUE ? 0 : level,
8486
8501
  useWebWorkers,
8487
8502
  encryptionStrength,
8488
8503
  extendedTimestamp,