@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/dist/zip.js CHANGED
@@ -217,6 +217,8 @@
217
217
  const ERR_INVALID_FUNCTION_OPTION = "Invalid option (must be a function)";
218
218
  const ERR_INVALID_SIGNAL = "Invalid signal (must be an AbortSignal instance)";
219
219
  const ERR_INVALID_PASSWORD_TYPE = "Invalid password (password must be a string, rawPassword must be a Uint8Array)";
220
+ const ERR_ABORTED = "The operation was aborted";
221
+ const ABORT_ERROR_NAME = "AbortError";
220
222
 
221
223
  function checkFunctionOption(value) {
222
224
  if (value && typeof value != FUNCTION_TYPE) {
@@ -232,6 +234,12 @@
232
234
  return signal || UNDEFINED_VALUE;
233
235
  }
234
236
 
237
+ function throwIfAborted(signal) {
238
+ if (signal && signal.aborted) {
239
+ throw signal.reason === UNDEFINED_VALUE ? new DOMException(ERR_ABORTED, ABORT_ERROR_NAME) : signal.reason;
240
+ }
241
+ }
242
+
235
243
  function checkPasswordOption(password, rawPassword) {
236
244
  if ((password && typeof password != STRING_TYPE) || (rawPassword && !(rawPassword instanceof Uint8Array))) {
237
245
  throw new Error(ERR_INVALID_PASSWORD_TYPE);
@@ -3760,11 +3768,13 @@
3760
3768
  const reader = this;
3761
3769
  const { sourceBlob, size } = reader;
3762
3770
  const { offset = 0, size: readSize = size - offset } = options || {};
3763
- if (!offset && readSize >= size) {
3764
- return toCompatibleReadable(sourceBlob.stream());
3765
- }
3766
- if (blobSliceReliable) {
3767
- return toCompatibleReadable(sourceBlob.slice(offset, offset + readSize).stream());
3771
+ if (typeof sourceBlob.stream == FUNCTION_TYPE) {
3772
+ if (!offset && readSize >= size) {
3773
+ return toCompatibleReadable(sourceBlob.stream());
3774
+ }
3775
+ if (blobSliceReliable) {
3776
+ return toCompatibleReadable(sourceBlob.slice(offset, offset + readSize).stream());
3777
+ }
3768
3778
  }
3769
3779
  return super.createReadable(options);
3770
3780
  }
@@ -5180,27 +5190,28 @@
5180
5190
  const { done, value } = await gen.next();
5181
5191
  if (done)
5182
5192
  return controller.close();
5183
- const chunk = {
5184
- ...value,
5185
- readable: (function () {
5186
- const { readable, writable } = new TransformStream();
5187
- if (value.getData) {
5188
- getData();
5189
- return readable;
5190
- }
5193
+ const entryReadable = (function () {
5194
+ const { readable, writable } = new TransformStream();
5195
+ if (value.getData) {
5196
+ getData();
5197
+ return readable;
5198
+ }
5191
5199
 
5192
- async function getData() {
5200
+ async function getData() {
5201
+ try {
5202
+ await value.getData(writable);
5203
+ } catch (error) {
5193
5204
  try {
5194
- await value.getData(writable);
5195
- } catch (error) {
5196
- try {
5197
- await writable.abort(error);
5198
- } catch {
5199
- // ignored
5200
- }
5205
+ await writable.abort(error);
5206
+ } catch {
5207
+ // ignored
5201
5208
  }
5202
5209
  }
5203
- })()
5210
+ }
5211
+ })();
5212
+ const chunk = {
5213
+ ...value,
5214
+ readable: entryReadable
5204
5215
  };
5205
5216
  delete chunk.getData;
5206
5217
  controller.enqueue(chunk);
@@ -5346,6 +5357,7 @@
5346
5357
  const size = compressedSize;
5347
5358
  const readable = toCompatibleReadable(reader.createReadable({ offset: dataOffset, size }));
5348
5359
  const signal = checkSignalOption(getOptionValue$1(zipEntry, options, OPTION_SIGNAL));
5360
+ throwIfAborted(signal);
5349
5361
  const checkPasswordOnly = getOptionValue$1(zipEntry, options, OPTION_CHECK_PASSWORD_ONLY);
5350
5362
  let checkOverlappingEntry = getOptionValue$1(zipEntry, options, OPTION_CHECK_OVERLAPPING_ENTRY);
5351
5363
  const checkOverlappingEntryOnly = getOptionValue$1(zipEntry, options, OPTION_CHECK_OVERLAPPING_ENTRY_ONLY);
@@ -6876,6 +6888,7 @@
6876
6888
  const createTempStream = getFunctionOptionValue(zipWriter, options, OPTION_CREATE_TEMP_STREAM);
6877
6889
  const dataDescriptorSignature = getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR_SIGNATURE, true);
6878
6890
  const signal = checkSignalOption(getOptionValue(zipWriter, options, OPTION_SIGNAL));
6891
+ throwIfAborted(signal);
6879
6892
  const useUnicodeFileNames = getOptionValue(zipWriter, options, OPTION_USE_UNICODE_FILE_NAMES, true);
6880
6893
  const compressionMethod = getOptionValue(zipWriter, options, PROPERTY_NAME_COMPRESSION_METHOD);
6881
6894
  const registeredCodec = passThrough || compressionMethod === UNDEFINED_VALUE ? UNDEFINED_VALUE : getRegisteredCodec(compressionMethod);
@@ -8543,7 +8556,7 @@
8543
8556
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8544
8557
  */
8545
8558
 
8546
- const VERSION = "2.11.3";
8559
+ const VERSION = "2.11.4";
8547
8560
 
8548
8561
  /*
8549
8562
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.