@zip.js/zip.js 2.8.35 → 2.8.37

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 (40) hide show
  1. package/deno.json +3 -2
  2. package/dist/zip-core.js +246 -55
  3. package/dist/zip-core.min.js +1 -1
  4. package/dist/zip-fs-core.js +198 -55
  5. package/dist/zip-fs-core.min.js +1 -1
  6. package/dist/zip-fs-native.js +249 -58
  7. package/dist/zip-fs-native.min.js +1 -1
  8. package/dist/zip-fs.js +247 -56
  9. package/dist/zip-fs.min.js +1 -1
  10. package/dist/zip-legacy.js +248 -57
  11. package/dist/zip-legacy.min.js +1 -1
  12. package/dist/zip-native.js +249 -58
  13. package/dist/zip-native.min.js +1 -1
  14. package/dist/zip-web-worker-native.js +1 -1
  15. package/dist/zip-web-worker.js +1 -1
  16. package/dist/zip.js +247 -56
  17. package/dist/zip.min.js +1 -1
  18. package/index-native.cjs +249 -58
  19. package/index-native.min.js +1 -1
  20. package/index.cjs +247 -56
  21. package/index.d.cts +112 -2
  22. package/index.d.ts +112 -2
  23. package/index.min.js +1 -1
  24. package/lib/core/codec-pool.js +19 -3
  25. package/lib/core/codec-registry.js +116 -0
  26. package/lib/core/constants.js +1 -1
  27. package/lib/core/io.js +47 -26
  28. package/lib/core/options.js +2 -0
  29. package/lib/core/streams/codec-stream.js +1 -1
  30. package/lib/core/streams/zip-entry-stream.js +22 -5
  31. package/lib/core/streams/zlib-js/zlib-streams.min.js +1 -1
  32. package/lib/core/web-worker-base.js +5 -1
  33. package/lib/core/web-worker-inline-native.js +1 -1
  34. package/lib/core/web-worker-inline-wasm.js +1 -1
  35. package/lib/core/zip-reader.js +6 -2
  36. package/lib/core/zip-writer.js +53 -18
  37. package/lib/zip-core-base.js +7 -0
  38. package/lib/zip-core-writer.js +1 -0
  39. package/package.json +1 -1
  40. package/worker-message-property-names.js +1 -1
package/index.d.cts CHANGED
@@ -202,6 +202,60 @@ export function configure(configuration: Configuration): void;
202
202
  */
203
203
  export function resetConfiguration(): void;
204
204
 
205
+ /**
206
+ * Registers a codec for a custom compression method (e.g. Zstandard, method 93). Entries using a
207
+ * registered method can then be written with `ZipWriter#add` and read with `FileEntry#getData`.
208
+ *
209
+ * Codecs registered with `CompressionStream`/`DecompressionStream` classes run on the main thread.
210
+ * Codecs registered with a `codecURI` module URL also run in web workers: the module is imported
211
+ * dynamically on both sides of the worker boundary.
212
+ *
213
+ * @param codec The codec definition.
214
+ */
215
+ export function registerCodec(codec: CodecDefinition): void;
216
+
217
+ /**
218
+ * Unregisters a codec previously registered with {@link registerCodec}.
219
+ *
220
+ * @param compressionMethod The compression method of the codec.
221
+ */
222
+ export function unregisterCodec(compressionMethod: number): void;
223
+
224
+ /**
225
+ * Represents a codec definition passed to {@link registerCodec}.
226
+ */
227
+ export interface CodecDefinition {
228
+ /**
229
+ * The compression method stored in zip entry headers (e.g. `93` for Zstandard). The values `0`
230
+ * (store), `8` (deflate), `9` (deflate64) and `99` (AES) are reserved.
231
+ */
232
+ compressionMethod: number;
233
+ /**
234
+ * The format name identifying the codec (e.g. `"zstd"`). It is passed as the first argument to
235
+ * the constructors of `CompressionStream` and `DecompressionStream`.
236
+ */
237
+ format: string;
238
+ /**
239
+ * The URL of a module exporting the `CompressionStream` and/or `DecompressionStream` classes of
240
+ * the codec. Relative URLs are resolved against `Configuration#baseURI`; passing an absolute URL
241
+ * (e.g. via `import.meta.resolve()`) is recommended.
242
+ */
243
+ codecURI?: string;
244
+ /**
245
+ * The stream implementation used to compress data, constructed with `(format, { level, chunkSize })`.
246
+ */
247
+ CompressionStream?: typeof TransformStreamLike;
248
+ /**
249
+ * The stream implementation used to decompress data, constructed with `(format, { chunkSize })`.
250
+ */
251
+ DecompressionStream?: typeof TransformStreamLike;
252
+ /**
253
+ * The minimum "version needed to extract" value written in zip entry headers (e.g. `63` for
254
+ * Zstandard).
255
+ */
256
+ versionNeeded?: number;
257
+ }
258
+
205
259
  /**
206
260
  * Represents the configuration passed to {@link configure}.
207
261
  */
@@ -662,6 +716,22 @@ export interface HttpRangeOptions {
662
716
  * @defaultValue true
663
717
  */
664
718
  checkResourceChanges?: boolean;
719
+ /**
720
+ * The maximum size in bytes of the range requests sent to read the data of an entry. The data is
721
+ * read with as many range requests as necessary, each response body being streamed, so that the
722
+ * size of a request never depends on the size of the entry.
723
+ *
724
+ * @remarks
725
+ * Because response bodies are streamed with backpressure, this value does not bound how much data
726
+ * is buffered in memory; it bounds the byte span, and therefore the lifetime, of each individual
727
+ * range request. Smaller windows keep each request short-lived, which avoids the idle or duration
728
+ * timeouts enforced by servers, CDNs and proxies when a slow consumer holds a connection open, and
729
+ * avoids relying on the server honoring very large ranges. Set it to `Infinity` to disable windowing
730
+ * and read each entry with a single range request covering its whole remaining length.
731
+ *
732
+ * @defaultValue 16777216
733
+ */
734
+ maximumRangeSize?: number;
665
735
  }
666
736
 
667
737
  /**
@@ -1968,11 +2038,21 @@ export interface ZipWriterConstructorOptions extends WorkerConfiguration {
1968
2038
  /**
1969
2039
  * `true` to store extended timestamp extra fields.
1970
2040
  *
1971
- * When set to `false`, the maximum last modification date cannot exceed November 31, 2107 and the maximum accuracy is 2 seconds.
2041
+ * When set to `false`, the maximum last modification date cannot exceed December 31, 2107 and the maximum accuracy is 2 seconds.
1972
2042
  *
1973
2043
  * @defaultValue true
1974
2044
  */
1975
2045
  extendedTimestamp?: boolean;
2046
+ /**
2047
+ * `true` to always store the NTFS extra field, `false` to never store it.
2048
+ *
2049
+ * By default, the NTFS extra field is stored only when it preserves information the extended timestamp extra field cannot
2050
+ * represent: a last modification date outside its supported range, or explicit {@link ZipWriterConstructorOptions#lastAccessDate}
2051
+ * or {@link ZipWriterConstructorOptions#creationDate} values.
2052
+ *
2053
+ * This option is ignored if the {@link ZipWriterConstructorOptions#extendedTimestamp} option is set to `false`.
2054
+ */
2055
+ ntfsTimestamp?: boolean;
1976
2056
  /**
1977
2057
  * `true` to use the ZipCrypto algorithm to encrypt the content of the entry. Setting it to `true` will also
1978
2058
  * set the {@link ZipWriterConstructorOptions#dataDescriptor} to `true`.
@@ -2088,7 +2168,10 @@ export interface ZipWriterConstructorOptions extends WorkerConfiguration {
2088
2168
  */
2089
2169
  supportZip64SplitFile?: boolean;
2090
2170
  /**
2091
- * `true`to produce zip files compatible with the USDZ specification.
2171
+ * `true`to produce zip files compatible with the USDZ specification: the data of the entries is aligned on 64-byte
2172
+ * boundaries and stored uncompressed unless the {@link ZipWriterConstructorOptions#level} or
2173
+ * {@link ZipWriterAddDataOptions#compressionMethod} options are set explicitly. Setting the
2174
+ * {@link ZipWriterConstructorOptions#password} option throws an {@link ERR_UNSUPPORTED_ENCRYPTION_USDZ} error.
2092
2175
  *
2093
2176
  * @defaultValue false
2094
2177
  */
@@ -2818,6 +2901,18 @@ export const ERR_UNSUPPORTED_ENCRYPTION: string;
2818
2901
  * Unsupported compression error
2819
2902
  */
2820
2903
  export const ERR_UNSUPPORTED_COMPRESSION: string;
2904
+ /**
2905
+ * Invalid codec definition error
2906
+ */
2907
+ export const ERR_INVALID_CODEC_DEFINITION: string;
2908
+ /**
2909
+ * Reserved compression method error
2910
+ */
2911
+ export const ERR_RESERVED_COMPRESSION_METHOD: string;
2912
+ /**
2913
+ * Invalid codec module error
2914
+ */
2915
+ export const ERR_INVALID_CODEC_MODULE: string;
2821
2916
  /**
2822
2917
  * Invalid signature error
2823
2918
  */
@@ -2828,6 +2923,17 @@ export const ERR_INVALID_SIGNATURE: string;
2828
2923
  export const ERR_INVALID_UNCOMPRESSED_SIZE: string;
2829
2924
  /**
2830
2925
  * Invalid compressed data error
2926
+ *
2927
+ * @remarks
2928
+ * The way malformed compressed data is reported is not uniform across codec
2929
+ * backends. Bytes trailing a complete DEFLATE stream (e.g. a wrong
2930
+ * `compressedSize`) are tolerated by the bundled WASM and pure-JS codecs, which
2931
+ * decompress the valid data and ignore the extra bytes, but are rejected by the
2932
+ * native `DecompressionStream` with its own `TypeError` (on Node,
2933
+ * `ERR_TRAILING_JUNK_AFTER_STREAM_END`) rather than this error. Any data that is
2934
+ * returned is always validated against the entry's uncompressed size (and CRC
2935
+ * when `checkSignature` is set), so it is never silently truncated; the backends
2936
+ * differ only in whether trailing bytes are ignored or raised as an error.
2831
2937
  */
2832
2938
  export const ERR_INVALID_COMPRESSED_DATA: string;
2833
2939
  /**
@@ -2866,6 +2972,10 @@ export const ERR_INVALID_EXTRAFIELD_DATA: string;
2866
2972
  * Invalid encryption strength error
2867
2973
  */
2868
2974
  export const ERR_INVALID_ENCRYPTION_STRENGTH: string;
2975
+ /**
2976
+ * Unsupported encryption in USDZ files error
2977
+ */
2978
+ export const ERR_UNSUPPORTED_ENCRYPTION_USDZ: string;
2869
2979
  /**
2870
2980
  * Invalid format error
2871
2981
  */
package/index.d.ts CHANGED
@@ -202,6 +202,60 @@ export function configure(configuration: Configuration): void;
202
202
  */
203
203
  export function resetConfiguration(): void;
204
204
 
205
+ /**
206
+ * Registers a codec for a custom compression method (e.g. Zstandard, method 93). Entries using a
207
+ * registered method can then be written with `ZipWriter#add` and read with `FileEntry#getData`.
208
+ *
209
+ * Codecs registered with `CompressionStream`/`DecompressionStream` classes run on the main thread.
210
+ * Codecs registered with a `codecURI` module URL also run in web workers: the module is imported
211
+ * dynamically on both sides of the worker boundary.
212
+ *
213
+ * @param codec The codec definition.
214
+ */
215
+ export function registerCodec(codec: CodecDefinition): void;
216
+
217
+ /**
218
+ * Unregisters a codec previously registered with {@link registerCodec}.
219
+ *
220
+ * @param compressionMethod The compression method of the codec.
221
+ */
222
+ export function unregisterCodec(compressionMethod: number): void;
223
+
224
+ /**
225
+ * Represents a codec definition passed to {@link registerCodec}.
226
+ */
227
+ export interface CodecDefinition {
228
+ /**
229
+ * The compression method stored in zip entry headers (e.g. `93` for Zstandard). The values `0`
230
+ * (store), `8` (deflate), `9` (deflate64) and `99` (AES) are reserved.
231
+ */
232
+ compressionMethod: number;
233
+ /**
234
+ * The format name identifying the codec (e.g. `"zstd"`). It is passed as the first argument to
235
+ * the constructors of `CompressionStream` and `DecompressionStream`.
236
+ */
237
+ format: string;
238
+ /**
239
+ * The URL of a module exporting the `CompressionStream` and/or `DecompressionStream` classes of
240
+ * the codec. Relative URLs are resolved against `Configuration#baseURI`; passing an absolute URL
241
+ * (e.g. via `import.meta.resolve()`) is recommended.
242
+ */
243
+ codecURI?: string;
244
+ /**
245
+ * The stream implementation used to compress data, constructed with `(format, { level, chunkSize })`.
246
+ */
247
+ CompressionStream?: typeof TransformStreamLike;
248
+ /**
249
+ * The stream implementation used to decompress data, constructed with `(format, { chunkSize })`.
250
+ */
251
+ DecompressionStream?: typeof TransformStreamLike;
252
+ /**
253
+ * The minimum "version needed to extract" value written in zip entry headers (e.g. `63` for
254
+ * Zstandard).
255
+ */
256
+ versionNeeded?: number;
257
+ }
258
+
205
259
  /**
206
260
  * Represents the configuration passed to {@link configure}.
207
261
  */
@@ -662,6 +716,22 @@ export interface HttpRangeOptions {
662
716
  * @defaultValue true
663
717
  */
664
718
  checkResourceChanges?: boolean;
719
+ /**
720
+ * The maximum size in bytes of the range requests sent to read the data of an entry. The data is
721
+ * read with as many range requests as necessary, each response body being streamed, so that the
722
+ * size of a request never depends on the size of the entry.
723
+ *
724
+ * @remarks
725
+ * Because response bodies are streamed with backpressure, this value does not bound how much data
726
+ * is buffered in memory; it bounds the byte span, and therefore the lifetime, of each individual
727
+ * range request. Smaller windows keep each request short-lived, which avoids the idle or duration
728
+ * timeouts enforced by servers, CDNs and proxies when a slow consumer holds a connection open, and
729
+ * avoids relying on the server honoring very large ranges. Set it to `Infinity` to disable windowing
730
+ * and read each entry with a single range request covering its whole remaining length.
731
+ *
732
+ * @defaultValue 16777216
733
+ */
734
+ maximumRangeSize?: number;
665
735
  }
666
736
 
667
737
  /**
@@ -1968,11 +2038,21 @@ export interface ZipWriterConstructorOptions extends WorkerConfiguration {
1968
2038
  /**
1969
2039
  * `true` to store extended timestamp extra fields.
1970
2040
  *
1971
- * When set to `false`, the maximum last modification date cannot exceed November 31, 2107 and the maximum accuracy is 2 seconds.
2041
+ * When set to `false`, the maximum last modification date cannot exceed December 31, 2107 and the maximum accuracy is 2 seconds.
1972
2042
  *
1973
2043
  * @defaultValue true
1974
2044
  */
1975
2045
  extendedTimestamp?: boolean;
2046
+ /**
2047
+ * `true` to always store the NTFS extra field, `false` to never store it.
2048
+ *
2049
+ * By default, the NTFS extra field is stored only when it preserves information the extended timestamp extra field cannot
2050
+ * represent: a last modification date outside its supported range, or explicit {@link ZipWriterConstructorOptions#lastAccessDate}
2051
+ * or {@link ZipWriterConstructorOptions#creationDate} values.
2052
+ *
2053
+ * This option is ignored if the {@link ZipWriterConstructorOptions#extendedTimestamp} option is set to `false`.
2054
+ */
2055
+ ntfsTimestamp?: boolean;
1976
2056
  /**
1977
2057
  * `true` to use the ZipCrypto algorithm to encrypt the content of the entry. Setting it to `true` will also
1978
2058
  * set the {@link ZipWriterConstructorOptions#dataDescriptor} to `true`.
@@ -2088,7 +2168,10 @@ export interface ZipWriterConstructorOptions extends WorkerConfiguration {
2088
2168
  */
2089
2169
  supportZip64SplitFile?: boolean;
2090
2170
  /**
2091
- * `true`to produce zip files compatible with the USDZ specification.
2171
+ * `true`to produce zip files compatible with the USDZ specification: the data of the entries is aligned on 64-byte
2172
+ * boundaries and stored uncompressed unless the {@link ZipWriterConstructorOptions#level} or
2173
+ * {@link ZipWriterAddDataOptions#compressionMethod} options are set explicitly. Setting the
2174
+ * {@link ZipWriterConstructorOptions#password} option throws an {@link ERR_UNSUPPORTED_ENCRYPTION_USDZ} error.
2092
2175
  *
2093
2176
  * @defaultValue false
2094
2177
  */
@@ -2818,6 +2901,18 @@ export const ERR_UNSUPPORTED_ENCRYPTION: string;
2818
2901
  * Unsupported compression error
2819
2902
  */
2820
2903
  export const ERR_UNSUPPORTED_COMPRESSION: string;
2904
+ /**
2905
+ * Invalid codec definition error
2906
+ */
2907
+ export const ERR_INVALID_CODEC_DEFINITION: string;
2908
+ /**
2909
+ * Reserved compression method error
2910
+ */
2911
+ export const ERR_RESERVED_COMPRESSION_METHOD: string;
2912
+ /**
2913
+ * Invalid codec module error
2914
+ */
2915
+ export const ERR_INVALID_CODEC_MODULE: string;
2821
2916
  /**
2822
2917
  * Invalid signature error
2823
2918
  */
@@ -2828,6 +2923,17 @@ export const ERR_INVALID_SIGNATURE: string;
2828
2923
  export const ERR_INVALID_UNCOMPRESSED_SIZE: string;
2829
2924
  /**
2830
2925
  * Invalid compressed data error
2926
+ *
2927
+ * @remarks
2928
+ * The way malformed compressed data is reported is not uniform across codec
2929
+ * backends. Bytes trailing a complete DEFLATE stream (e.g. a wrong
2930
+ * `compressedSize`) are tolerated by the bundled WASM and pure-JS codecs, which
2931
+ * decompress the valid data and ignore the extra bytes, but are rejected by the
2932
+ * native `DecompressionStream` with its own `TypeError` (on Node,
2933
+ * `ERR_TRAILING_JUNK_AFTER_STREAM_END`) rather than this error. Any data that is
2934
+ * returned is always validated against the entry's uncompressed size (and CRC
2935
+ * when `checkSignature` is set), so it is never silently truncated; the backends
2936
+ * differ only in whether trailing bytes are ignored or raised as an error.
2831
2937
  */
2832
2938
  export const ERR_INVALID_COMPRESSED_DATA: string;
2833
2939
  /**
@@ -2866,6 +2972,10 @@ export const ERR_INVALID_EXTRAFIELD_DATA: string;
2866
2972
  * Invalid encryption strength error
2867
2973
  */
2868
2974
  export const ERR_INVALID_ENCRYPTION_STRENGTH: string;
2975
+ /**
2976
+ * Unsupported encryption in USDZ files error
2977
+ */
2978
+ export const ERR_UNSUPPORTED_ENCRYPTION_USDZ: string;
2869
2979
  /**
2870
2980
  * Invalid format error
2871
2981
  */