@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.
@@ -208,6 +208,8 @@ const STRICTNESS_TOLERANT = "tolerant";
208
208
  const ERR_INVALID_FUNCTION_OPTION = "Invalid option (must be a function)";
209
209
  const ERR_INVALID_SIGNAL = "Invalid signal (must be an AbortSignal instance)";
210
210
  const ERR_INVALID_PASSWORD_TYPE = "Invalid password (password must be a string, rawPassword must be a Uint8Array)";
211
+ const ERR_ABORTED = "The operation was aborted";
212
+ const ABORT_ERROR_NAME = "AbortError";
211
213
 
212
214
  function checkFunctionOption(value) {
213
215
  if (value && typeof value != FUNCTION_TYPE) {
@@ -223,6 +225,12 @@ function checkSignalOption(signal) {
223
225
  return signal || UNDEFINED_VALUE;
224
226
  }
225
227
 
228
+ function throwIfAborted(signal) {
229
+ if (signal && signal.aborted) {
230
+ throw signal.reason === UNDEFINED_VALUE ? new DOMException(ERR_ABORTED, ABORT_ERROR_NAME) : signal.reason;
231
+ }
232
+ }
233
+
226
234
  function checkPasswordOption(password, rawPassword) {
227
235
  if ((password && typeof password != STRING_TYPE) || (rawPassword && !(rawPassword instanceof Uint8Array))) {
228
236
  throw new Error(ERR_INVALID_PASSWORD_TYPE);
@@ -3785,11 +3793,13 @@ class BlobReader extends Reader {
3785
3793
  const reader = this;
3786
3794
  const { sourceBlob, size } = reader;
3787
3795
  const { offset = 0, size: readSize = size - offset } = options || {};
3788
- if (!offset && readSize >= size) {
3789
- return toCompatibleReadable(sourceBlob.stream());
3790
- }
3791
- if (blobSliceReliable) {
3792
- return toCompatibleReadable(sourceBlob.slice(offset, offset + readSize).stream());
3796
+ if (typeof sourceBlob.stream == FUNCTION_TYPE) {
3797
+ if (!offset && readSize >= size) {
3798
+ return toCompatibleReadable(sourceBlob.stream());
3799
+ }
3800
+ if (blobSliceReliable) {
3801
+ return toCompatibleReadable(sourceBlob.slice(offset, offset + readSize).stream());
3802
+ }
3793
3803
  }
3794
3804
  return super.createReadable(options);
3795
3805
  }
@@ -5225,27 +5235,28 @@ class ZipReaderStream {
5225
5235
  const { done, value } = await gen.next();
5226
5236
  if (done)
5227
5237
  return controller.close();
5228
- const chunk = {
5229
- ...value,
5230
- readable: (function () {
5231
- const { readable, writable } = new TransformStream();
5232
- if (value.getData) {
5233
- getData();
5234
- return readable;
5235
- }
5238
+ const entryReadable = (function () {
5239
+ const { readable, writable } = new TransformStream();
5240
+ if (value.getData) {
5241
+ getData();
5242
+ return readable;
5243
+ }
5236
5244
 
5237
- async function getData() {
5245
+ async function getData() {
5246
+ try {
5247
+ await value.getData(writable);
5248
+ } catch (error) {
5238
5249
  try {
5239
- await value.getData(writable);
5240
- } catch (error) {
5241
- try {
5242
- await writable.abort(error);
5243
- } catch {
5244
- // ignored
5245
- }
5250
+ await writable.abort(error);
5251
+ } catch {
5252
+ // ignored
5246
5253
  }
5247
5254
  }
5248
- })()
5255
+ }
5256
+ })();
5257
+ const chunk = {
5258
+ ...value,
5259
+ readable: entryReadable
5249
5260
  };
5250
5261
  delete chunk.getData;
5251
5262
  controller.enqueue(chunk);
@@ -5391,6 +5402,7 @@ let ZipEntry$1 = class ZipEntry {
5391
5402
  const size = compressedSize;
5392
5403
  const readable = toCompatibleReadable(reader.createReadable({ offset: dataOffset, size }));
5393
5404
  const signal = checkSignalOption(getOptionValue$1(zipEntry, options, OPTION_SIGNAL));
5405
+ throwIfAborted(signal);
5394
5406
  const checkPasswordOnly = getOptionValue$1(zipEntry, options, OPTION_CHECK_PASSWORD_ONLY);
5395
5407
  let checkOverlappingEntry = getOptionValue$1(zipEntry, options, OPTION_CHECK_OVERLAPPING_ENTRY);
5396
5408
  const checkOverlappingEntryOnly = getOptionValue$1(zipEntry, options, OPTION_CHECK_OVERLAPPING_ENTRY_ONLY);
@@ -6921,6 +6933,7 @@ function resolveMetadata(zipWriter, name, options) {
6921
6933
  const createTempStream = getFunctionOptionValue(zipWriter, options, OPTION_CREATE_TEMP_STREAM);
6922
6934
  const dataDescriptorSignature = getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR_SIGNATURE, true);
6923
6935
  const signal = checkSignalOption(getOptionValue(zipWriter, options, OPTION_SIGNAL));
6936
+ throwIfAborted(signal);
6924
6937
  const useUnicodeFileNames = getOptionValue(zipWriter, options, OPTION_USE_UNICODE_FILE_NAMES, true);
6925
6938
  const compressionMethod = getOptionValue(zipWriter, options, PROPERTY_NAME_COMPRESSION_METHOD);
6926
6939
  const registeredCodec = passThrough || compressionMethod === UNDEFINED_VALUE ? UNDEFINED_VALUE : getRegisteredCodec(compressionMethod);
@@ -8665,7 +8678,7 @@ function formatSupported(StreamClass, format) {
8665
8678
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8666
8679
  */
8667
8680
 
8668
- const VERSION = "2.11.3";
8681
+ const VERSION = "2.11.4";
8669
8682
 
8670
8683
  /*
8671
8684
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
@@ -9538,8 +9551,6 @@ const ERR_INVALID_PASS_THROUGH = "Invalid passThrough option (use readerOptions.
9538
9551
  const ERR_INVALID_READER_OPTIONS = "Invalid readerOptions (must be an object)";
9539
9552
  const ERR_ZIP_CRYPTO_LAST_MOD_DATE = "The last modification date of an entry encrypted with ZipCrypto cannot be changed when passThrough is set";
9540
9553
  const ERR_ABORT_EXPORT = "zipjs-abort-export";
9541
- const ERR_ABORTED = "The operation was aborted";
9542
- const ABORT_ERROR_NAME = "AbortError";
9543
9554
  const INFOZIP_EXTRA_FIELD_TYPE = "infozip";
9544
9555
  const INTERPRETED_EXTRA_FIELD_TYPES = new Set([
9545
9556
  EXTRAFIELD_TYPE_ZIP64,