@zip.js/zip.js 2.11.3 → 2.11.4

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
@@ -237,11 +237,13 @@ class BlobReader extends Reader {
237
237
  const reader = this;
238
238
  const { sourceBlob, size } = reader;
239
239
  const { offset = 0, size: readSize = size - offset } = options || {};
240
- if (!offset && readSize >= size) {
241
- return toCompatibleReadable(sourceBlob.stream());
242
- }
243
- if (blobSliceReliable) {
244
- return toCompatibleReadable(sourceBlob.slice(offset, offset + readSize).stream());
240
+ if (typeof sourceBlob.stream == FUNCTION_TYPE) {
241
+ if (!offset && readSize >= size) {
242
+ return toCompatibleReadable(sourceBlob.stream());
243
+ }
244
+ if (blobSliceReliable) {
245
+ return toCompatibleReadable(sourceBlob.slice(offset, offset + readSize).stream());
246
+ }
245
247
  }
246
248
  return super.createReadable(options);
247
249
  }
@@ -26,6 +26,8 @@
26
26
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
27
  */
28
28
 
29
+ /* global DOMException */
30
+
29
31
  import {
30
32
  BOOLEAN_TYPE,
31
33
  FUNCTION_TYPE,
@@ -86,6 +88,8 @@ const STRICTNESS_TOLERANT = "tolerant";
86
88
  const ERR_INVALID_FUNCTION_OPTION = "Invalid option (must be a function)";
87
89
  const ERR_INVALID_SIGNAL = "Invalid signal (must be an AbortSignal instance)";
88
90
  const ERR_INVALID_PASSWORD_TYPE = "Invalid password (password must be a string, rawPassword must be a Uint8Array)";
91
+ const ERR_ABORTED = "The operation was aborted";
92
+ const ABORT_ERROR_NAME = "AbortError";
89
93
 
90
94
  export {
91
95
  OPTION_FILENAME_ENCODING,
@@ -140,8 +144,11 @@ export {
140
144
  ERR_INVALID_FUNCTION_OPTION,
141
145
  ERR_INVALID_SIGNAL,
142
146
  ERR_INVALID_PASSWORD_TYPE,
147
+ ERR_ABORTED,
148
+ ABORT_ERROR_NAME,
143
149
  checkFunctionOption,
144
150
  checkSignalOption,
151
+ throwIfAborted,
145
152
  checkPasswordOption,
146
153
  checkInteger,
147
154
  checkIntegerOption,
@@ -162,6 +169,12 @@ function checkSignalOption(signal) {
162
169
  return signal || UNDEFINED_VALUE;
163
170
  }
164
171
 
172
+ function throwIfAborted(signal) {
173
+ if (signal && signal.aborted) {
174
+ throw signal.reason === UNDEFINED_VALUE ? new DOMException(ERR_ABORTED, ABORT_ERROR_NAME) : signal.reason;
175
+ }
176
+ }
177
+
165
178
  function checkPasswordOption(password, rawPassword) {
166
179
  if ((password && typeof password != STRING_TYPE) || (rawPassword && !(rawPassword instanceof Uint8Array))) {
167
180
  throw new Error(ERR_INVALID_PASSWORD_TYPE);
@@ -26,6 +26,6 @@
26
26
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
27
  */
28
28
 
29
- const VERSION = "2.11.3";
29
+ const VERSION = "2.11.4";
30
30
 
31
31
  export { VERSION };
@@ -55,7 +55,7 @@ import {
55
55
  import {
56
56
  Entry
57
57
  } from "./zip-entry.js";
58
- import { checkSignalOption } from "./options.js";
58
+ import { checkSignalOption, ERR_ABORTED, ABORT_ERROR_NAME } from "./options.js";
59
59
  import { ProgressWatcherStream, callHandler } from "./codec-worker.js";
60
60
  import {
61
61
  UNDEFINED_VALUE,
@@ -92,8 +92,6 @@ const ERR_INVALID_PASS_THROUGH = "Invalid passThrough option (use readerOptions.
92
92
  const ERR_INVALID_READER_OPTIONS = "Invalid readerOptions (must be an object)";
93
93
  const ERR_ZIP_CRYPTO_LAST_MOD_DATE = "The last modification date of an entry encrypted with ZipCrypto cannot be changed when passThrough is set";
94
94
  const ERR_ABORT_EXPORT = "zipjs-abort-export";
95
- const ERR_ABORTED = "The operation was aborted";
96
- const ABORT_ERROR_NAME = "AbortError";
97
95
  const INFOZIP_EXTRA_FIELD_TYPE = "infozip";
98
96
  const INTERPRETED_EXTRA_FIELD_TYPES = new Set([
99
97
  EXTRAFIELD_TYPE_ZIP64,
@@ -173,6 +173,7 @@ import {
173
173
  OPTION_PREVENT_CLOSE,
174
174
  checkFunctionOption,
175
175
  checkSignalOption,
176
+ throwIfAborted,
176
177
  checkPasswordOption,
177
178
  toNumber
178
179
  } from "./options.js";
@@ -668,27 +669,28 @@ class ZipReaderStream {
668
669
  const { done, value } = await gen.next();
669
670
  if (done)
670
671
  return controller.close();
671
- const chunk = {
672
- ...value,
673
- readable: (function () {
674
- const { readable, writable } = new TransformStream();
675
- if (value.getData) {
676
- getData();
677
- return readable;
678
- }
672
+ const entryReadable = (function () {
673
+ const { readable, writable } = new TransformStream();
674
+ if (value.getData) {
675
+ getData();
676
+ return readable;
677
+ }
679
678
 
680
- async function getData() {
679
+ async function getData() {
680
+ try {
681
+ await value.getData(writable);
682
+ } catch (error) {
681
683
  try {
682
- await value.getData(writable);
683
- } catch (error) {
684
- try {
685
- await writable.abort(error);
686
- } catch {
687
- // ignored
688
- }
684
+ await writable.abort(error);
685
+ } catch {
686
+ // ignored
689
687
  }
690
688
  }
691
- })()
689
+ }
690
+ })();
691
+ const chunk = {
692
+ ...value,
693
+ readable: entryReadable
692
694
  };
693
695
  delete chunk.getData;
694
696
  controller.enqueue(chunk);
@@ -880,6 +882,7 @@ class ZipEntry {
880
882
  const size = compressedSize;
881
883
  const readable = toCompatibleReadable(reader.createReadable({ offset: dataOffset, size }));
882
884
  const signal = checkSignalOption(getOptionValue(zipEntry, options, OPTION_SIGNAL));
885
+ throwIfAborted(signal);
883
886
  const checkPasswordOnly = getOptionValue(zipEntry, options, OPTION_CHECK_PASSWORD_ONLY);
884
887
  let checkOverlappingEntry = getOptionValue(zipEntry, options, OPTION_CHECK_OVERLAPPING_ENTRY);
885
888
  const checkOverlappingEntryOnly = getOptionValue(zipEntry, options, OPTION_CHECK_OVERLAPPING_ENTRY_ONLY);
@@ -238,6 +238,7 @@ import {
238
238
  ERR_INVALID_PASSWORD_TYPE,
239
239
  checkFunctionOption,
240
240
  checkSignalOption,
241
+ throwIfAborted,
241
242
  checkPasswordOption,
242
243
  checkInteger,
243
244
  checkIntegerOption,
@@ -918,6 +919,7 @@ function resolveMetadata(zipWriter, name, options) {
918
919
  const createTempStream = getFunctionOptionValue(zipWriter, options, OPTION_CREATE_TEMP_STREAM);
919
920
  const dataDescriptorSignature = getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR_SIGNATURE, true);
920
921
  const signal = checkSignalOption(getOptionValue(zipWriter, options, OPTION_SIGNAL));
922
+ throwIfAborted(signal);
921
923
  const useUnicodeFileNames = getOptionValue(zipWriter, options, OPTION_USE_UNICODE_FILE_NAMES, true);
922
924
  const compressionMethod = getOptionValue(zipWriter, options, PROPERTY_NAME_COMPRESSION_METHOD);
923
925
  const registeredCodec = passThrough || compressionMethod === UNDEFINED_VALUE ? UNDEFINED_VALUE : getRegisteredCodec(compressionMethod);
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.11.3",
6
+ "version": "2.11.4",
7
7
  "type": "module",
8
8
  "keywords": [
9
9
  "zip",