@zip.js/zip.js 2.8.30 → 2.8.32

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.
Files changed (56) hide show
  1. package/BENCHMARKS.md +82 -1
  2. package/deno.json +5 -4
  3. package/dist/zip-core.js +403 -339
  4. package/dist/zip-core.min.js +1 -1
  5. package/dist/zip-fs-core.js +116 -278
  6. package/dist/zip-fs-core.min.js +1 -1
  7. package/dist/zip-fs-native.js +440 -378
  8. package/dist/zip-fs-native.min.js +1 -1
  9. package/dist/zip-fs.js +439 -377
  10. package/dist/zip-fs.min.js +1 -1
  11. package/dist/zip-legacy.js +408 -344
  12. package/dist/zip-legacy.min.js +1 -1
  13. package/dist/zip-module.wasm +0 -0
  14. package/dist/zip-native.js +411 -347
  15. package/dist/zip-native.min.js +1 -1
  16. package/dist/zip-web-worker-native.js +1 -1
  17. package/dist/zip-web-worker.js +1 -1
  18. package/dist/zip.js +410 -346
  19. package/dist/zip.min.js +1 -1
  20. package/index-native.cjs +440 -378
  21. package/index-native.min.js +1 -1
  22. package/index.cjs +439 -377
  23. package/index.d.cts +2853 -0
  24. package/index.d.ts +278 -1
  25. package/index.min.js +1 -1
  26. package/lib/core/codec-worker.js +1 -11
  27. package/lib/core/configuration.js +21 -33
  28. package/lib/core/constants.js +3 -0
  29. package/lib/core/io.js +11 -19
  30. package/lib/core/streams/aes-crypto-stream.js +16 -20
  31. package/lib/core/streams/common-crypto.js +0 -2
  32. package/lib/core/streams/zip-crypto-stream.js +12 -16
  33. package/lib/core/streams/zip-entry-stream.js +2 -32
  34. package/lib/core/streams/zlib-js/zlib-streams.min.js +1 -1
  35. package/lib/core/streams/zlib-wasm/zlib-streams-loader.js +1 -3
  36. package/lib/core/streams/zlib-wasm/zlib-streams.wasm +0 -0
  37. package/lib/core/util/base64.js +68 -0
  38. package/lib/core/util/blob-temp-stream.js +124 -0
  39. package/lib/core/util/decode-text.js +0 -1
  40. package/lib/core/util/default-mime-type.js +0 -3
  41. package/lib/core/util/inflate.js +194 -0
  42. package/lib/core/util/mime-type.js +26 -22
  43. package/lib/core/util/opfs-temp-stream.js +1 -37
  44. package/lib/core/util/sync-access-handle-temp-stream.js +147 -0
  45. package/lib/core/web-worker-inline-native.js +1 -1
  46. package/lib/core/web-worker-inline-template-native.js +5 -5
  47. package/lib/core/web-worker-inline-wasm.js +1 -1
  48. package/lib/core/zip-fs.js +6 -13
  49. package/lib/core/zip-reader.js +48 -127
  50. package/lib/core/zip-writer.js +27 -45
  51. package/lib/core/zlib-streams-inline-template.js +3 -2
  52. package/lib/core/zlib-streams-inline.js +1 -1
  53. package/lib/zip-core-base.js +10 -2
  54. package/package.json +9 -6
  55. package/reserved-property-names.js +50 -0
  56. package/lib/core/util/mini-lz.js +0 -198
package/index.d.ts CHANGED
@@ -381,6 +381,45 @@ export interface OPFSTempStreamOptions {
381
381
  */
382
382
  export function createOPFSTempStream(options?: OPFSTempStreamOptions): () => Promise<TempStream>;
383
383
 
384
+ /**
385
+ * Options for {@link createBlobTempStream}.
386
+ */
387
+ export interface BlobTempStreamOptions {
388
+ /**
389
+ * Spill a buffered entry to a `Blob` once its buffered data exceeds this size, in bytes. Smaller entries stay in memory.
390
+ *
391
+ * @defaultValue 1048576
392
+ */
393
+ thresholdBytes?: number;
394
+ }
395
+
396
+ /**
397
+ * Builds a {@link ZipWriterConstructorOptions.createTempStream} factory that spills the data of buffered entries into a `Blob` instead of keeping it in memory.
398
+ *
399
+ * An entry stays in memory until it exceeds `thresholdBytes`, then its data is transferred incrementally into a `Blob` built with `new Response(stream).blob()` and streamed back afterwards.
400
+ * In Chromium-based browsers, `Blob` data is managed outside the page and paged to disk under memory pressure, so peak memory stays bounded on large buffered entries without any storage permission or cleanup obligation.
401
+ * In Firefox, the `Blob` stays in memory but the helper still reduces peak memory usage moderately (roughly 30% on large entries) by releasing staged chunks earlier.
402
+ * In Safari, building the `Blob` retains several copies of the staged data (roughly 4 times the entry size at peak); do not use this helper there.
403
+ * In non-browser runtimes, the helper stays functional but roughly doubles peak memory usage (staged bytes plus their `Blob` copy).
404
+ * Outside Chromium-based browsers, prefer {@link createOPFSTempStream} or a file-backed implementation.
405
+ *
406
+ * @param options The options.
407
+ * @returns A factory suitable for {@link ZipWriterConstructorOptions.createTempStream}.
408
+ */
409
+ export function createBlobTempStream(options?: BlobTempStreamOptions): () => TempStream;
410
+
411
+ /**
412
+ * Builds a {@link ZipWriterConstructorOptions.createTempStream} factory that spills the data of buffered entries to the Origin Private File System (OPFS) via `FileSystemSyncAccessHandle` instead of keeping it in memory.
413
+ *
414
+ * This is the fastest disk-backed temporary storage on the web platform: it behaves like {@link createOPFSTempStream} (same options, same bounded-memory profile) but writes roughly 2.5 times faster in Chromium and Firefox and reads back several times faster in Firefox and Safari, making disk-backed staging nearly as fast as the in-memory default.
415
+ *
416
+ * `FileSystemSyncAccessHandle` is only exposed in dedicated workers, so this helper requires running the {@link ZipWriter} inside a worker; it throws when created in an unsupported context unless `getDirectory` is provided.
417
+ *
418
+ * @param options The options.
419
+ * @returns A factory suitable for {@link ZipWriterConstructorOptions.createTempStream}.
420
+ */
421
+ export function createSyncAccessHandleTempStream(options?: OPFSTempStreamOptions): () => TempStream;
422
+
384
423
  /**
385
424
  * Represents an instance used to read or write unknown type of data.
386
425
  *
@@ -392,6 +431,10 @@ export interface Initializable {
392
431
  * Initializes the instance asynchronously
393
432
  */
394
433
  init?(): Promise<void>;
434
+ /**
435
+ * `true` if the instance is initialized.
436
+ */
437
+ initialized?: boolean;
395
438
  }
396
439
 
397
440
  /**
@@ -700,6 +743,22 @@ export class SplitDataWriter implements Initializable, WritableWriter {
700
743
  * The `WritableStream` instance.
701
744
  */
702
745
  writable: WritableStream;
746
+ /**
747
+ * The number of the disk being written.
748
+ */
749
+ diskNumber: number;
750
+ /**
751
+ * The byte offset of the disk being written.
752
+ */
753
+ diskOffset: number;
754
+ /**
755
+ * The maximum size of each disk in bytes.
756
+ */
757
+ maxSize: number;
758
+ /**
759
+ * The number of bytes still available on the disk being written.
760
+ */
761
+ availableSize: number;
703
762
  /**
704
763
  * Initializes the instance asynchronously
705
764
  */
@@ -1028,6 +1087,168 @@ export interface ZipReaderOptions {
1028
1087
  preventClose?: boolean;
1029
1088
  }
1030
1089
 
1090
+ /**
1091
+ * Represents the parsed general purpose bit flag of an entry.
1092
+ */
1093
+ export interface EntryBitFlag {
1094
+ /**
1095
+ * The compression option bits.
1096
+ */
1097
+ level: number;
1098
+ /**
1099
+ * `true` if the entry data is followed by a data descriptor.
1100
+ */
1101
+ dataDescriptor: boolean;
1102
+ /**
1103
+ * `true` if the filename and the comment are encoded in UTF-8 (EFS).
1104
+ */
1105
+ languageEncodingFlag: boolean;
1106
+ }
1107
+ /**
1108
+ * Represents an extra field record of an entry.
1109
+ */
1110
+ export interface EntryExtraField {
1111
+ /**
1112
+ * The type (header id) of the extra field.
1113
+ */
1114
+ type: number;
1115
+ /**
1116
+ * The data of the extra field.
1117
+ */
1118
+ data: Uint8Array;
1119
+ }
1120
+ /**
1121
+ * Represents the AES extra field record of an entry.
1122
+ */
1123
+ export interface EntryExtraFieldAES extends EntryExtraField {
1124
+ /**
1125
+ * The encryption strength (1, 2 or 3).
1126
+ */
1127
+ strength?: number;
1128
+ /**
1129
+ * The compression method stored in the AES extra field.
1130
+ */
1131
+ originalCompressionMethod?: number;
1132
+ }
1133
+ /**
1134
+ * Represents a Unicode path or comment extra field record of an entry.
1135
+ */
1136
+ export interface EntryExtraFieldUnicode extends EntryExtraField {
1137
+ /**
1138
+ * `true` if the extra field is consistent with the entry metadata.
1139
+ */
1140
+ valid?: boolean;
1141
+ }
1142
+ /**
1143
+ * Represents the local file header fields of an entry, read when getting the entry data.
1144
+ */
1145
+ export interface LocalDirectory {
1146
+ /**
1147
+ * The "Version" field.
1148
+ */
1149
+ version: number;
1150
+ /**
1151
+ * `true` if the entry is encrypted.
1152
+ */
1153
+ encrypted: boolean;
1154
+ /**
1155
+ * The general purpose bit flag (raw).
1156
+ */
1157
+ rawBitFlag: number;
1158
+ /**
1159
+ * The general purpose bit flag.
1160
+ */
1161
+ bitFlag: EntryBitFlag;
1162
+ /**
1163
+ * The last modification date (raw).
1164
+ */
1165
+ rawLastModDate: number;
1166
+ /**
1167
+ * The last modification date.
1168
+ */
1169
+ lastModDate: Date;
1170
+ /**
1171
+ * The length of the filename in bytes.
1172
+ */
1173
+ filenameLength: number;
1174
+ /**
1175
+ * The length of the extra field in bytes.
1176
+ */
1177
+ extraFieldLength: number;
1178
+ /**
1179
+ * The extra field (raw).
1180
+ */
1181
+ rawExtraField: Uint8Array;
1182
+ /**
1183
+ * The extra field.
1184
+ */
1185
+ extraField?: Map<number, EntryExtraField>;
1186
+ /**
1187
+ * The signature (CRC32 checksum) of the content.
1188
+ */
1189
+ signature?: number;
1190
+ /**
1191
+ * The compressed size of the content.
1192
+ */
1193
+ compressedSize?: number;
1194
+ /**
1195
+ * The uncompressed size of the content.
1196
+ */
1197
+ uncompressedSize?: number;
1198
+ /**
1199
+ * The compression method.
1200
+ */
1201
+ compressionMethod?: number;
1202
+ /**
1203
+ * The Zip64 extra field.
1204
+ */
1205
+ extraFieldZip64?: EntryExtraField;
1206
+ /**
1207
+ * The AES extra field.
1208
+ */
1209
+ extraFieldAES?: EntryExtraFieldAES;
1210
+ /**
1211
+ * The NTFS extra field.
1212
+ */
1213
+ extraFieldNTFS?: EntryExtraField;
1214
+ /**
1215
+ * The Unix extra field.
1216
+ */
1217
+ extraFieldUnix?: EntryExtraField;
1218
+ /**
1219
+ * The Info-ZIP Unix extra field.
1220
+ */
1221
+ extraFieldInfoZip?: EntryExtraField;
1222
+ /**
1223
+ * The extended timestamp extra field.
1224
+ */
1225
+ extraFieldExtendedTimestamp?: EntryExtraField;
1226
+ /**
1227
+ * The Unicode path extra field.
1228
+ */
1229
+ extraFieldUnicodePath?: EntryExtraFieldUnicode;
1230
+ /**
1231
+ * The Unicode comment extra field.
1232
+ */
1233
+ extraFieldUnicodeComment?: EntryExtraFieldUnicode;
1234
+ /**
1235
+ * The USDZ extra field.
1236
+ */
1237
+ extraFieldUSDZ?: EntryExtraField;
1238
+ }
1239
+ /**
1240
+ * Represents an error raised while processing an entry, decorated with entry context.
1241
+ */
1242
+ export interface EntryError extends Error {
1243
+ /**
1244
+ * `true` if the zip file is corrupted because the entry data could not be written entirely.
1245
+ */
1246
+ corruptedEntry?: boolean;
1247
+ /**
1248
+ * The id of the related {@link ZipEntry} (filesystem API).
1249
+ */
1250
+ entryId?: number;
1251
+ }
1031
1252
  /**
1032
1253
  * Represents the metadata of an entry in a zip file (Core API).
1033
1254
  */
@@ -1225,6 +1446,62 @@ export interface EntryMetaData {
1225
1446
  * The compression method.
1226
1447
  */
1227
1448
  compressionMethod: number;
1449
+ /**
1450
+ * The general purpose bit flag (raw).
1451
+ */
1452
+ rawBitFlag?: number;
1453
+ /**
1454
+ * The general purpose bit flag.
1455
+ */
1456
+ bitFlag?: EntryBitFlag;
1457
+ /**
1458
+ * The length of the filename in bytes.
1459
+ */
1460
+ filenameLength?: number;
1461
+ /**
1462
+ * The length of the extra field in bytes.
1463
+ */
1464
+ extraFieldLength?: number;
1465
+ /**
1466
+ * The Zip64 extra field.
1467
+ */
1468
+ extraFieldZip64?: EntryExtraField;
1469
+ /**
1470
+ * The AES extra field.
1471
+ */
1472
+ extraFieldAES?: EntryExtraFieldAES;
1473
+ /**
1474
+ * The NTFS extra field.
1475
+ */
1476
+ extraFieldNTFS?: EntryExtraField;
1477
+ /**
1478
+ * The Unix extra field.
1479
+ */
1480
+ extraFieldUnix?: EntryExtraField;
1481
+ /**
1482
+ * The Info-ZIP Unix extra field.
1483
+ */
1484
+ extraFieldInfoZip?: EntryExtraField;
1485
+ /**
1486
+ * The extended timestamp extra field.
1487
+ */
1488
+ extraFieldExtendedTimestamp?: EntryExtraField;
1489
+ /**
1490
+ * The Unicode path extra field.
1491
+ */
1492
+ extraFieldUnicodePath?: EntryExtraFieldUnicode;
1493
+ /**
1494
+ * The Unicode comment extra field.
1495
+ */
1496
+ extraFieldUnicodeComment?: EntryExtraFieldUnicode;
1497
+ /**
1498
+ * The USDZ extra field.
1499
+ */
1500
+ extraFieldUSDZ?: EntryExtraField;
1501
+ /**
1502
+ * The local file header fields, set when the entry data has been read.
1503
+ */
1504
+ localDirectory?: LocalDirectory;
1228
1505
  }
1229
1506
  export interface DirectoryEntry extends EntryMetaData {
1230
1507
  /**
@@ -1585,7 +1862,7 @@ export interface ZipWriterConstructorOptions extends WorkerConfiguration {
1585
1862
  * The `writable` side receives compressed entry data. The `readable` side is consumed when the entry is replayed into the final zip stream.
1586
1863
  * The optional `dispose` method is called once the entry has been processed (on success, error, or abort) so a resource-backed buffer can release its resource.
1587
1864
  *
1588
- * See {@link createOPFSTempStream} for a ready-made OPFS-backed implementation.
1865
+ * See {@link createOPFSTempStream} for a ready-made OPFS-backed implementation, {@link createSyncAccessHandleTempStream} for a faster worker-only variant, and {@link createBlobTempStream} for a `Blob`-backed one.
1589
1866
  */
1590
1867
  createTempStream?: () => TempStream | Promise<TempStream>;
1591
1868
  /**