@zip.js/zip.js 2.7.40 → 2.7.41

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/lib/core/io.js CHANGED
@@ -31,7 +31,8 @@
31
31
 
32
32
  import {
33
33
  UNDEFINED_VALUE,
34
- FUNCTION_TYPE
34
+ FUNCTION_TYPE,
35
+ END_OF_CENTRAL_DIR_LENGTH
35
36
  } from "./constants.js";
36
37
  import { getConfiguration } from "./configuration.js";
37
38
 
@@ -296,35 +297,43 @@ function createHttpReader(httpReader, url, options) {
296
297
  const {
297
298
  preventHeadRequest,
298
299
  useRangeHeader,
299
- forceRangeRequests
300
+ forceRangeRequests,
301
+ combineSizeEocd
300
302
  } = options;
301
303
  options = Object.assign({}, options);
302
304
  delete options.preventHeadRequest;
303
305
  delete options.useRangeHeader;
304
306
  delete options.forceRangeRequests;
307
+ delete options.combineSizeEocd;
305
308
  delete options.useXHR;
306
309
  Object.assign(httpReader, {
307
310
  url,
308
311
  options,
309
312
  preventHeadRequest,
310
313
  useRangeHeader,
311
- forceRangeRequests
314
+ forceRangeRequests,
315
+ combineSizeEocd
312
316
  });
313
317
  }
314
318
 
315
319
  async function initHttpReader(httpReader, sendRequest, getRequestData) {
316
320
  const {
317
321
  url,
322
+ preventHeadRequest,
318
323
  useRangeHeader,
319
- forceRangeRequests
324
+ forceRangeRequests,
325
+ combineSizeEocd
320
326
  } = httpReader;
321
- if (isHttpFamily(url) && (useRangeHeader || forceRangeRequests)) {
322
- const { headers } = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader));
323
- if (!forceRangeRequests && headers.get(HTTP_HEADER_ACCEPT_RANGES) != HTTP_RANGE_UNIT) {
327
+ if (isHttpFamily(url) && (useRangeHeader || forceRangeRequests) && (typeof preventHeadRequest == "undefined" || preventHeadRequest)) {
328
+ const response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader, combineSizeEocd ? -END_OF_CENTRAL_DIR_LENGTH : undefined));
329
+ if (!forceRangeRequests && response.headers.get(HTTP_HEADER_ACCEPT_RANGES) != HTTP_RANGE_UNIT) {
324
330
  throw new Error(ERR_HTTP_RANGE);
325
331
  } else {
332
+ if (combineSizeEocd) {
333
+ httpReader.eocdCache = new Uint8Array(await response.arrayBuffer());
334
+ }
326
335
  let contentSize;
327
- const contentRangeHeader = headers.get(HTTP_HEADER_CONTENT_RANGE);
336
+ const contentRangeHeader = response.headers.get(HTTP_HEADER_CONTENT_RANGE);
328
337
  if (contentRangeHeader) {
329
338
  const splitHeader = contentRangeHeader.trim().split(/\s*\/\s*/);
330
339
  if (splitHeader.length) {
@@ -349,9 +358,14 @@ async function readUint8ArrayHttpReader(httpReader, index, length, sendRequest,
349
358
  const {
350
359
  useRangeHeader,
351
360
  forceRangeRequests,
361
+ eocdCache,
362
+ size,
352
363
  options
353
364
  } = httpReader;
354
365
  if (useRangeHeader || forceRangeRequests) {
366
+ if (eocdCache && index == size - END_OF_CENTRAL_DIR_LENGTH && length == END_OF_CENTRAL_DIR_LENGTH) {
367
+ return eocdCache;
368
+ }
355
369
  const response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader, index, length));
356
370
  if (response.status != 206) {
357
371
  throw new Error(ERR_HTTP_RANGE);
@@ -367,7 +381,7 @@ async function readUint8ArrayHttpReader(httpReader, index, length, sendRequest,
367
381
  }
368
382
 
369
383
  function getRangeHeaders(httpReader, index = 0, length = 1) {
370
- return Object.assign({}, getHeaders(httpReader), { [HTTP_HEADER_RANGE]: HTTP_RANGE_UNIT + "=" + index + "-" + (index + length - 1) });
384
+ return Object.assign({}, getHeaders(httpReader), { [HTTP_HEADER_RANGE]: HTTP_RANGE_UNIT + "=" + (index < 0 ? index : index + "-" + (index + length - 1)) });
371
385
  }
372
386
 
373
387
  function getHeaders({ options }) {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "A JavaScript library to zip and unzip files in the browser, Deno and Node.js",
4
4
  "author": "Gildas Lormeau",
5
5
  "license": "BSD-3-Clause",
6
- "version": "2.7.40",
6
+ "version": "2.7.41",
7
7
  "type": "module",
8
8
  "keywords": [
9
9
  "zip",