@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-fs.js CHANGED
@@ -2779,35 +2779,43 @@
2779
2779
  const {
2780
2780
  preventHeadRequest,
2781
2781
  useRangeHeader,
2782
- forceRangeRequests
2782
+ forceRangeRequests,
2783
+ combineSizeEocd
2783
2784
  } = options;
2784
2785
  options = Object.assign({}, options);
2785
2786
  delete options.preventHeadRequest;
2786
2787
  delete options.useRangeHeader;
2787
2788
  delete options.forceRangeRequests;
2789
+ delete options.combineSizeEocd;
2788
2790
  delete options.useXHR;
2789
2791
  Object.assign(httpReader, {
2790
2792
  url,
2791
2793
  options,
2792
2794
  preventHeadRequest,
2793
2795
  useRangeHeader,
2794
- forceRangeRequests
2796
+ forceRangeRequests,
2797
+ combineSizeEocd
2795
2798
  });
2796
2799
  }
2797
2800
 
2798
2801
  async function initHttpReader(httpReader, sendRequest, getRequestData) {
2799
2802
  const {
2800
2803
  url,
2804
+ preventHeadRequest,
2801
2805
  useRangeHeader,
2802
- forceRangeRequests
2806
+ forceRangeRequests,
2807
+ combineSizeEocd
2803
2808
  } = httpReader;
2804
- if (isHttpFamily(url) && (useRangeHeader || forceRangeRequests)) {
2805
- const { headers } = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader));
2806
- if (!forceRangeRequests && headers.get(HTTP_HEADER_ACCEPT_RANGES) != HTTP_RANGE_UNIT) {
2809
+ if (isHttpFamily(url) && (useRangeHeader || forceRangeRequests) && (typeof preventHeadRequest == "undefined" || preventHeadRequest)) {
2810
+ const response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader, combineSizeEocd ? -END_OF_CENTRAL_DIR_LENGTH : undefined));
2811
+ if (!forceRangeRequests && response.headers.get(HTTP_HEADER_ACCEPT_RANGES) != HTTP_RANGE_UNIT) {
2807
2812
  throw new Error(ERR_HTTP_RANGE);
2808
2813
  } else {
2814
+ if (combineSizeEocd) {
2815
+ httpReader.eocdCache = new Uint8Array(await response.arrayBuffer());
2816
+ }
2809
2817
  let contentSize;
2810
- const contentRangeHeader = headers.get(HTTP_HEADER_CONTENT_RANGE);
2818
+ const contentRangeHeader = response.headers.get(HTTP_HEADER_CONTENT_RANGE);
2811
2819
  if (contentRangeHeader) {
2812
2820
  const splitHeader = contentRangeHeader.trim().split(/\s*\/\s*/);
2813
2821
  if (splitHeader.length) {
@@ -2832,9 +2840,14 @@
2832
2840
  const {
2833
2841
  useRangeHeader,
2834
2842
  forceRangeRequests,
2843
+ eocdCache,
2844
+ size,
2835
2845
  options
2836
2846
  } = httpReader;
2837
2847
  if (useRangeHeader || forceRangeRequests) {
2848
+ if (eocdCache && index == size - END_OF_CENTRAL_DIR_LENGTH && length == END_OF_CENTRAL_DIR_LENGTH) {
2849
+ return eocdCache;
2850
+ }
2838
2851
  const response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader, index, length));
2839
2852
  if (response.status != 206) {
2840
2853
  throw new Error(ERR_HTTP_RANGE);
@@ -2850,7 +2863,7 @@
2850
2863
  }
2851
2864
 
2852
2865
  function getRangeHeaders(httpReader, index = 0, length = 1) {
2853
- return Object.assign({}, getHeaders(httpReader), { [HTTP_HEADER_RANGE]: HTTP_RANGE_UNIT + "=" + index + "-" + (index + length - 1) });
2866
+ return Object.assign({}, getHeaders(httpReader), { [HTTP_HEADER_RANGE]: HTTP_RANGE_UNIT + "=" + (index < 0 ? index : index + "-" + (index + length - 1)) });
2854
2867
  }
2855
2868
 
2856
2869
  function getHeaders({ options }) {
@@ -3545,9 +3558,10 @@
3545
3558
  commentUTF8,
3546
3559
  rawExtraField: directoryArray.subarray(extraFieldOffset, commentOffset)
3547
3560
  });
3561
+ const decode = getOptionValue$1(zipReader, options, "decodeText") || decodeText;
3548
3562
  const [filename, comment] = await Promise.all([
3549
- decodeText(rawFilename, filenameUTF8 ? CHARSET_UTF8 : filenameEncoding || CHARSET_CP437),
3550
- decodeText(rawComment, commentUTF8 ? CHARSET_UTF8 : commentEncoding || CHARSET_CP437)
3563
+ decode(rawFilename, filenameUTF8 ? CHARSET_UTF8 : filenameEncoding || CHARSET_CP437),
3564
+ decode(rawComment, commentUTF8 ? CHARSET_UTF8 : commentEncoding || CHARSET_CP437)
3551
3565
  ]);
3552
3566
  Object.assign(fileEntry, {
3553
3567
  rawComment,
@@ -4151,12 +4165,13 @@
4151
4165
  } else {
4152
4166
  options.directory = name.endsWith(DIRECTORY_SIGNATURE);
4153
4167
  }
4154
- const rawFilename = encodeText(name);
4168
+ const encode = getOptionValue(zipWriter, options, "encodeText", encodeText);
4169
+ const rawFilename = encode(name);
4155
4170
  if (getLength(rawFilename) > MAX_16_BITS) {
4156
4171
  throw new Error(ERR_INVALID_ENTRY_NAME);
4157
4172
  }
4158
4173
  const comment = options.comment || "";
4159
- const rawComment = encodeText(comment);
4174
+ const rawComment = encode(comment);
4160
4175
  if (getLength(rawComment) > MAX_16_BITS) {
4161
4176
  throw new Error(ERR_INVALID_ENTRY_COMMENT);
4162
4177
  }
@@ -4259,7 +4274,7 @@
4259
4274
  zip64DiskNumberStart,
4260
4275
  password,
4261
4276
  rawPassword,
4262
- level,
4277
+ level: !useCompressionStream && zipWriter.config.CompressionStream === UNDEFINED_VALUE ? 0 : level,
4263
4278
  useWebWorkers,
4264
4279
  encryptionStrength,
4265
4280
  extendedTimestamp,