@zip.js/zip.js 2.8.36 → 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.
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
  */
@@ -667,6 +721,14 @@ export interface HttpRangeOptions {
667
721
  * read with as many range requests as necessary, each response body being streamed, so that the
668
722
  * size of a request never depends on the size of the entry.
669
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
+ *
670
732
  * @defaultValue 16777216
671
733
  */
672
734
  maximumRangeSize?: number;
@@ -1976,11 +2038,21 @@ export interface ZipWriterConstructorOptions extends WorkerConfiguration {
1976
2038
  /**
1977
2039
  * `true` to store extended timestamp extra fields.
1978
2040
  *
1979
- * 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.
1980
2042
  *
1981
2043
  * @defaultValue true
1982
2044
  */
1983
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;
1984
2056
  /**
1985
2057
  * `true` to use the ZipCrypto algorithm to encrypt the content of the entry. Setting it to `true` will also
1986
2058
  * set the {@link ZipWriterConstructorOptions#dataDescriptor} to `true`.
@@ -2096,7 +2168,10 @@ export interface ZipWriterConstructorOptions extends WorkerConfiguration {
2096
2168
  */
2097
2169
  supportZip64SplitFile?: boolean;
2098
2170
  /**
2099
- * `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.
2100
2175
  *
2101
2176
  * @defaultValue false
2102
2177
  */
@@ -2826,6 +2901,18 @@ export const ERR_UNSUPPORTED_ENCRYPTION: string;
2826
2901
  * Unsupported compression error
2827
2902
  */
2828
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;
2829
2916
  /**
2830
2917
  * Invalid signature error
2831
2918
  */
@@ -2836,6 +2923,17 @@ export const ERR_INVALID_SIGNATURE: string;
2836
2923
  export const ERR_INVALID_UNCOMPRESSED_SIZE: string;
2837
2924
  /**
2838
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.
2839
2937
  */
2840
2938
  export const ERR_INVALID_COMPRESSED_DATA: string;
2841
2939
  /**
@@ -2874,6 +2972,10 @@ export const ERR_INVALID_EXTRAFIELD_DATA: string;
2874
2972
  * Invalid encryption strength error
2875
2973
  */
2876
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;
2877
2979
  /**
2878
2980
  * Invalid format error
2879
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
  */
@@ -667,6 +721,14 @@ export interface HttpRangeOptions {
667
721
  * read with as many range requests as necessary, each response body being streamed, so that the
668
722
  * size of a request never depends on the size of the entry.
669
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
+ *
670
732
  * @defaultValue 16777216
671
733
  */
672
734
  maximumRangeSize?: number;
@@ -1976,11 +2038,21 @@ export interface ZipWriterConstructorOptions extends WorkerConfiguration {
1976
2038
  /**
1977
2039
  * `true` to store extended timestamp extra fields.
1978
2040
  *
1979
- * 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.
1980
2042
  *
1981
2043
  * @defaultValue true
1982
2044
  */
1983
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;
1984
2056
  /**
1985
2057
  * `true` to use the ZipCrypto algorithm to encrypt the content of the entry. Setting it to `true` will also
1986
2058
  * set the {@link ZipWriterConstructorOptions#dataDescriptor} to `true`.
@@ -2096,7 +2168,10 @@ export interface ZipWriterConstructorOptions extends WorkerConfiguration {
2096
2168
  */
2097
2169
  supportZip64SplitFile?: boolean;
2098
2170
  /**
2099
- * `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.
2100
2175
  *
2101
2176
  * @defaultValue false
2102
2177
  */
@@ -2826,6 +2901,18 @@ export const ERR_UNSUPPORTED_ENCRYPTION: string;
2826
2901
  * Unsupported compression error
2827
2902
  */
2828
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;
2829
2916
  /**
2830
2917
  * Invalid signature error
2831
2918
  */
@@ -2836,6 +2923,17 @@ export const ERR_INVALID_SIGNATURE: string;
2836
2923
  export const ERR_INVALID_UNCOMPRESSED_SIZE: string;
2837
2924
  /**
2838
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.
2839
2937
  */
2840
2938
  export const ERR_INVALID_COMPRESSED_DATA: string;
2841
2939
  /**
@@ -2874,6 +2972,10 @@ export const ERR_INVALID_EXTRAFIELD_DATA: string;
2874
2972
  * Invalid encryption strength error
2875
2973
  */
2876
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;
2877
2979
  /**
2878
2980
  * Invalid format error
2879
2981
  */