@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/deno.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@zip-js/zip-js",
3
- "version": "2.7.40",
3
+ "version": "2.7.41",
4
4
  "exports": "./index.js"
5
5
  }
@@ -8633,35 +8633,43 @@
8633
8633
  const {
8634
8634
  preventHeadRequest,
8635
8635
  useRangeHeader,
8636
- forceRangeRequests
8636
+ forceRangeRequests,
8637
+ combineSizeEocd
8637
8638
  } = options;
8638
8639
  options = Object.assign({}, options);
8639
8640
  delete options.preventHeadRequest;
8640
8641
  delete options.useRangeHeader;
8641
8642
  delete options.forceRangeRequests;
8643
+ delete options.combineSizeEocd;
8642
8644
  delete options.useXHR;
8643
8645
  Object.assign(httpReader, {
8644
8646
  url,
8645
8647
  options,
8646
8648
  preventHeadRequest,
8647
8649
  useRangeHeader,
8648
- forceRangeRequests
8650
+ forceRangeRequests,
8651
+ combineSizeEocd
8649
8652
  });
8650
8653
  }
8651
8654
 
8652
8655
  async function initHttpReader(httpReader, sendRequest, getRequestData) {
8653
8656
  const {
8654
8657
  url,
8658
+ preventHeadRequest,
8655
8659
  useRangeHeader,
8656
- forceRangeRequests
8660
+ forceRangeRequests,
8661
+ combineSizeEocd
8657
8662
  } = httpReader;
8658
- if (isHttpFamily(url) && (useRangeHeader || forceRangeRequests)) {
8659
- const { headers } = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader));
8660
- if (!forceRangeRequests && headers.get(HTTP_HEADER_ACCEPT_RANGES) != HTTP_RANGE_UNIT) {
8663
+ if (isHttpFamily(url) && (useRangeHeader || forceRangeRequests) && (typeof preventHeadRequest == "undefined" || preventHeadRequest)) {
8664
+ const response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader, combineSizeEocd ? -END_OF_CENTRAL_DIR_LENGTH : undefined));
8665
+ if (!forceRangeRequests && response.headers.get(HTTP_HEADER_ACCEPT_RANGES) != HTTP_RANGE_UNIT) {
8661
8666
  throw new Error(ERR_HTTP_RANGE);
8662
8667
  } else {
8668
+ if (combineSizeEocd) {
8669
+ httpReader.eocdCache = new Uint8Array(await response.arrayBuffer());
8670
+ }
8663
8671
  let contentSize;
8664
- const contentRangeHeader = headers.get(HTTP_HEADER_CONTENT_RANGE);
8672
+ const contentRangeHeader = response.headers.get(HTTP_HEADER_CONTENT_RANGE);
8665
8673
  if (contentRangeHeader) {
8666
8674
  const splitHeader = contentRangeHeader.trim().split(/\s*\/\s*/);
8667
8675
  if (splitHeader.length) {
@@ -8686,9 +8694,14 @@
8686
8694
  const {
8687
8695
  useRangeHeader,
8688
8696
  forceRangeRequests,
8697
+ eocdCache,
8698
+ size,
8689
8699
  options
8690
8700
  } = httpReader;
8691
8701
  if (useRangeHeader || forceRangeRequests) {
8702
+ if (eocdCache && index == size - END_OF_CENTRAL_DIR_LENGTH && length == END_OF_CENTRAL_DIR_LENGTH) {
8703
+ return eocdCache;
8704
+ }
8692
8705
  const response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader, index, length));
8693
8706
  if (response.status != 206) {
8694
8707
  throw new Error(ERR_HTTP_RANGE);
@@ -8704,7 +8717,7 @@
8704
8717
  }
8705
8718
 
8706
8719
  function getRangeHeaders(httpReader, index = 0, length = 1) {
8707
- return Object.assign({}, getHeaders(httpReader), { [HTTP_HEADER_RANGE]: HTTP_RANGE_UNIT + "=" + index + "-" + (index + length - 1) });
8720
+ return Object.assign({}, getHeaders(httpReader), { [HTTP_HEADER_RANGE]: HTTP_RANGE_UNIT + "=" + (index < 0 ? index : index + "-" + (index + length - 1)) });
8708
8721
  }
8709
8722
 
8710
8723
  function getHeaders({ options }) {
@@ -9399,9 +9412,10 @@
9399
9412
  commentUTF8,
9400
9413
  rawExtraField: directoryArray.subarray(extraFieldOffset, commentOffset)
9401
9414
  });
9415
+ const decode = getOptionValue$1(zipReader, options, "decodeText") || decodeText;
9402
9416
  const [filename, comment] = await Promise.all([
9403
- decodeText(rawFilename, filenameUTF8 ? CHARSET_UTF8 : filenameEncoding || CHARSET_CP437),
9404
- decodeText(rawComment, commentUTF8 ? CHARSET_UTF8 : commentEncoding || CHARSET_CP437)
9417
+ decode(rawFilename, filenameUTF8 ? CHARSET_UTF8 : filenameEncoding || CHARSET_CP437),
9418
+ decode(rawComment, commentUTF8 ? CHARSET_UTF8 : commentEncoding || CHARSET_CP437)
9405
9419
  ]);
9406
9420
  Object.assign(fileEntry, {
9407
9421
  rawComment,
@@ -10005,12 +10019,13 @@
10005
10019
  } else {
10006
10020
  options.directory = name.endsWith(DIRECTORY_SIGNATURE);
10007
10021
  }
10008
- const rawFilename = encodeText(name);
10022
+ const encode = getOptionValue(zipWriter, options, "encodeText", encodeText);
10023
+ const rawFilename = encode(name);
10009
10024
  if (getLength(rawFilename) > MAX_16_BITS) {
10010
10025
  throw new Error(ERR_INVALID_ENTRY_NAME);
10011
10026
  }
10012
10027
  const comment = options.comment || "";
10013
- const rawComment = encodeText(comment);
10028
+ const rawComment = encode(comment);
10014
10029
  if (getLength(rawComment) > MAX_16_BITS) {
10015
10030
  throw new Error(ERR_INVALID_ENTRY_COMMENT);
10016
10031
  }
@@ -10113,7 +10128,7 @@
10113
10128
  zip64DiskNumberStart,
10114
10129
  password,
10115
10130
  rawPassword,
10116
- level,
10131
+ level: !useCompressionStream && zipWriter.config.CompressionStream === UNDEFINED_VALUE ? 0 : level,
10117
10132
  useWebWorkers,
10118
10133
  encryptionStrength,
10119
10134
  extendedTimestamp,