@zip.js/zip.js 2.8.45 → 2.8.47
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/README.md +28 -2
- package/deno.json +13 -3
- package/dist/zip-core-external.js +146 -35
- package/dist/zip-core-external.min.js +1 -1
- package/dist/zip-core.js +154 -32
- package/dist/zip-core.min.js +1 -1
- package/dist/zip-fs-core-external.js +146 -35
- package/dist/zip-fs-core-external.min.js +1 -1
- package/dist/zip-fs-core.js +124 -30
- package/dist/zip-fs-core.min.js +1 -1
- package/dist/zip-fs-external.js +146 -35
- package/dist/zip-fs-external.min.js +1 -1
- package/dist/zip-fs-native.js +160 -36
- package/dist/zip-fs-native.min.js +1 -1
- package/dist/zip-fs.js +160 -36
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-legacy.js +156 -34
- package/dist/zip-legacy.min.js +1 -1
- package/dist/zip-native.js +158 -36
- package/dist/zip-native.min.js +1 -1
- package/dist/zip-web-worker-native.js +1 -1
- package/dist/zip-web-worker.js +1 -1
- package/dist/zip.js +158 -36
- package/dist/zip.min.js +1 -1
- package/index-native.cjs +160 -36
- package/index-native.min.js +1 -1
- package/index.cjs +160 -36
- package/index.d.cts +232 -1
- package/index.d.ts +232 -1
- package/index.min.js +1 -1
- package/lib/core/codec-pool.js +9 -5
- package/lib/core/codec-worker.js +30 -13
- package/lib/core/configuration.js +20 -2
- package/lib/core/constants.js +2 -0
- package/lib/core/options.js +4 -0
- package/lib/core/streams/codec-stream.js +2 -0
- package/lib/core/streams/common-crypto.js +2 -1
- package/lib/core/streams/zip-entry-stream.js +12 -10
- package/lib/core/util/sync-access-handle-temp-stream.js +2 -1
- package/lib/core/web-worker-base.js +27 -0
- package/lib/core/web-worker-inline-native.js +1 -1
- package/lib/core/web-worker-inline-wasm.js +1 -1
- package/lib/core/web-worker-native.js +7 -9
- package/lib/core/web-worker-wasm.js +9 -12
- package/lib/core/zip-fs.js +1 -1
- package/lib/core/zip-reader.js +58 -5
- package/lib/core/zip-writer.js +43 -8
- package/lib/zip-core-base.js +2 -1
- package/lib/{core/web-worker-inline-template.js → zip-core-custom.js} +13 -20
- package/lib/zip-core-reader.js +2 -1
- package/lib/zip-core-writer.js +10 -1
- package/lib/zip-module-native.js +3 -3
- package/lib/zip-module-wasm-base.js +3 -3
- package/package.json +20 -2
- package/lib/core/web-worker-inline-template-native.js +0 -48
- package/lib/core/zlib-streams-inline-template.js +0 -45
package/index.d.cts
CHANGED
|
@@ -314,6 +314,19 @@ export interface Configuration extends WorkerConfiguration {
|
|
|
314
314
|
* @defaultValue "./core/web-worker.js"
|
|
315
315
|
*/
|
|
316
316
|
workerURI?: string;
|
|
317
|
+
/**
|
|
318
|
+
* The function used to create the web workers, taking precedence over `workerURI`.
|
|
319
|
+
*
|
|
320
|
+
* It lets bundlers detect the worker script statically and compile it with its imports, e.g. a custom worker script embedding alternative compression streams.
|
|
321
|
+
*
|
|
322
|
+
* Here is an example with a custom worker script (see {@link initWorker} for the content of the script):
|
|
323
|
+
* ```
|
|
324
|
+
* configure({
|
|
325
|
+
* createWorker: () => new Worker(new URL("./zip-worker.js", import.meta.url), { type: "module" })
|
|
326
|
+
* });
|
|
327
|
+
* ```
|
|
328
|
+
*/
|
|
329
|
+
createWorker?: () => Worker;
|
|
317
330
|
/**
|
|
318
331
|
* The URI of the WebAssembly module used by default implementations to compress/decompress data. It is ignored if `useCompressionStream` is set to `true` and `CompressionStream`/`DecompressionStream` are supported by the environment.
|
|
319
332
|
*
|
|
@@ -352,12 +365,20 @@ export interface Configuration extends WorkerConfiguration {
|
|
|
352
365
|
*
|
|
353
366
|
* @defaultValue {@link CodecStream}
|
|
354
367
|
*/
|
|
355
|
-
|
|
368
|
+
CompressionStreamFallback?: typeof TransformStreamLike;
|
|
356
369
|
/**
|
|
357
370
|
* The stream implementation used to decompress data when `useCompressionStream` is set to `false`.
|
|
358
371
|
*
|
|
359
372
|
* @defaultValue {@link CodecStream}
|
|
360
373
|
*/
|
|
374
|
+
DecompressionStreamFallback?: typeof TransformStreamLike;
|
|
375
|
+
/**
|
|
376
|
+
* @deprecated Use {@link Configuration#CompressionStreamFallback} instead.
|
|
377
|
+
*/
|
|
378
|
+
CompressionStreamZlib?: typeof TransformStreamLike;
|
|
379
|
+
/**
|
|
380
|
+
* @deprecated Use {@link Configuration#DecompressionStreamFallback} instead.
|
|
381
|
+
*/
|
|
361
382
|
DecompressionStreamZlib?: typeof TransformStreamLike;
|
|
362
383
|
}
|
|
363
384
|
|
|
@@ -390,6 +411,75 @@ export interface WorkerConfiguration {
|
|
|
390
411
|
*/
|
|
391
412
|
export function terminateWorkers(): Promise<void>;
|
|
392
413
|
|
|
414
|
+
/**
|
|
415
|
+
* Initializes a custom web worker script. This function is exposed by the `@zip.js/zip.js/worker` entry point and must be called
|
|
416
|
+
* in the worker script created by {@link Configuration#createWorker} or referenced by {@link Configuration#workerURI}.
|
|
417
|
+
*
|
|
418
|
+
* Here is a complete example of a worker script using fflate as the compression engine, e.g. to reduce the bundle size:
|
|
419
|
+
* ```
|
|
420
|
+
* import { initWorker } from "@zip.js/zip.js/worker";
|
|
421
|
+
* import { Deflate, Inflate } from "fflate";
|
|
422
|
+
*
|
|
423
|
+
* const FORMAT_DEFLATE_RAW = "deflate-raw";
|
|
424
|
+
*
|
|
425
|
+
* class FflateStream extends TransformStream {
|
|
426
|
+
* constructor(codec) {
|
|
427
|
+
* super({
|
|
428
|
+
* start(controller) {
|
|
429
|
+
* codec.ondata = chunk => {
|
|
430
|
+
* if (chunk.length) {
|
|
431
|
+
* controller.enqueue(chunk);
|
|
432
|
+
* }
|
|
433
|
+
* };
|
|
434
|
+
* },
|
|
435
|
+
* transform(chunk) {
|
|
436
|
+
* codec.push(chunk);
|
|
437
|
+
* },
|
|
438
|
+
* flush() {
|
|
439
|
+
* codec.push(new Uint8Array(0), true);
|
|
440
|
+
* }
|
|
441
|
+
* });
|
|
442
|
+
* }
|
|
443
|
+
* }
|
|
444
|
+
*
|
|
445
|
+
* class CompressionStreamFallback extends FflateStream {
|
|
446
|
+
* constructor(format, { level } = {}) {
|
|
447
|
+
* checkFormat(format);
|
|
448
|
+
* super(new Deflate(level === undefined ? {} : { level }));
|
|
449
|
+
* }
|
|
450
|
+
* }
|
|
451
|
+
*
|
|
452
|
+
* class DecompressionStreamFallback extends FflateStream {
|
|
453
|
+
* constructor(format) {
|
|
454
|
+
* checkFormat(format);
|
|
455
|
+
* super(new Inflate());
|
|
456
|
+
* }
|
|
457
|
+
* }
|
|
458
|
+
*
|
|
459
|
+
* function checkFormat(format) {
|
|
460
|
+
* if (format != FORMAT_DEFLATE_RAW) {
|
|
461
|
+
* throw new TypeError("Unsupported compression format: " + format);
|
|
462
|
+
* }
|
|
463
|
+
* }
|
|
464
|
+
*
|
|
465
|
+
* initWorker({ CompressionStreamFallback, DecompressionStreamFallback });
|
|
466
|
+
* ```
|
|
467
|
+
*/
|
|
468
|
+
export function initWorker(options?: {
|
|
469
|
+
/**
|
|
470
|
+
* The stream implementation used to compress data when `useCompressionStream` is set to `false` or when `CompressionStream` is unsupported.
|
|
471
|
+
*/
|
|
472
|
+
CompressionStreamFallback?: typeof TransformStreamLike;
|
|
473
|
+
/**
|
|
474
|
+
* The stream implementation used to decompress data when `useCompressionStream` is set to `false` or when `DecompressionStream` is unsupported.
|
|
475
|
+
*/
|
|
476
|
+
DecompressionStreamFallback?: typeof TransformStreamLike;
|
|
477
|
+
/**
|
|
478
|
+
* The function called before resolving the stream implementations, e.g. to load a WebAssembly module.
|
|
479
|
+
*/
|
|
480
|
+
init?(config: Configuration): Promise<unknown> | unknown;
|
|
481
|
+
}): void;
|
|
482
|
+
|
|
393
483
|
/**
|
|
394
484
|
* Represents a class implementing `CompressionStream` or `DecompressionStream` interfaces.
|
|
395
485
|
*/
|
|
@@ -1029,6 +1119,21 @@ export class ZipReader<Type> {
|
|
|
1029
1119
|
* The data appended after the zip file.
|
|
1030
1120
|
*/
|
|
1031
1121
|
appendedData?: Uint8Array;
|
|
1122
|
+
/**
|
|
1123
|
+
* The data of the digital signature record of the central directory (see
|
|
1124
|
+
* {@link ZipWriterCloseOptions#signCentralDirectory}), if the zip file contains one. zip.js does not verify
|
|
1125
|
+
* signatures; use {@link ZipReader#directoryOffset} and {@link ZipReader#directoryLength} to read the signed
|
|
1126
|
+
* central directory data and verify it.
|
|
1127
|
+
*/
|
|
1128
|
+
digitalSignature?: Uint8Array;
|
|
1129
|
+
/**
|
|
1130
|
+
* The offset of the central directory in the zip file.
|
|
1131
|
+
*/
|
|
1132
|
+
directoryOffset?: number;
|
|
1133
|
+
/**
|
|
1134
|
+
* The length in bytes of the central directory as declared in the end of central directory record.
|
|
1135
|
+
*/
|
|
1136
|
+
directoryLength?: number;
|
|
1032
1137
|
/**
|
|
1033
1138
|
* Returns all the entries in the zip file
|
|
1034
1139
|
*
|
|
@@ -1144,6 +1249,66 @@ export interface GetEntriesOptions {
|
|
|
1144
1249
|
* {@link ERR_AMBIGUOUS_ARCHIVE} error otherwise.
|
|
1145
1250
|
*/
|
|
1146
1251
|
maxAppendedDataSize?: number;
|
|
1252
|
+
/**
|
|
1253
|
+
* The function called for decrypting the central directory when it is encrypted (see the Strong Encryption
|
|
1254
|
+
* Specification in the ZIP format specification). Without this function, reading such an archive throws an
|
|
1255
|
+
* {@link ERR_ENCRYPTED_CENTRAL_DIRECTORY} error. zip.js provides the encrypted data and the related metadata
|
|
1256
|
+
* but does not implement the decryption itself.
|
|
1257
|
+
*
|
|
1258
|
+
* @param data The raw data stored in place of the central directory, i.e. the decryption header followed by
|
|
1259
|
+
* the encrypted (and possibly compressed) central directory, as stored in the zip file.
|
|
1260
|
+
* @param encryptionInfo The encryption metadata read from the Zip64 end of central directory record, or
|
|
1261
|
+
* `undefined` if the zip file does not contain a version 2 record.
|
|
1262
|
+
* @returns The decrypted and decompressed central directory records.
|
|
1263
|
+
*/
|
|
1264
|
+
decryptCentralDirectory?(
|
|
1265
|
+
data: Uint8Array,
|
|
1266
|
+
encryptionInfo?: DirectoryEncryptionInfo
|
|
1267
|
+
): Uint8Array | PromiseLike<Uint8Array>;
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
/**
|
|
1271
|
+
* Represents the encryption metadata of an encrypted central directory (see
|
|
1272
|
+
* {@link GetEntriesOptions#decryptCentralDirectory}), read from the version 2 Zip64 end of central directory
|
|
1273
|
+
* record.
|
|
1274
|
+
*/
|
|
1275
|
+
export interface DirectoryEncryptionInfo {
|
|
1276
|
+
/**
|
|
1277
|
+
* The raw data of the extensible data sector of the record.
|
|
1278
|
+
*/
|
|
1279
|
+
rawExtensibleData: Uint8Array;
|
|
1280
|
+
/**
|
|
1281
|
+
* The compression method applied to the central directory before encryption.
|
|
1282
|
+
*/
|
|
1283
|
+
compressionMethod?: number;
|
|
1284
|
+
/**
|
|
1285
|
+
* The size of the compressed and encrypted central directory.
|
|
1286
|
+
*/
|
|
1287
|
+
compressedSize?: number;
|
|
1288
|
+
/**
|
|
1289
|
+
* The size of the central directory once decrypted and decompressed.
|
|
1290
|
+
*/
|
|
1291
|
+
uncompressedSize?: number;
|
|
1292
|
+
/**
|
|
1293
|
+
* The identifier of the encryption algorithm (e.g. `0x6610` for AES-256).
|
|
1294
|
+
*/
|
|
1295
|
+
encryptionAlgorithm?: number;
|
|
1296
|
+
/**
|
|
1297
|
+
* The key size in bits.
|
|
1298
|
+
*/
|
|
1299
|
+
bitLength?: number;
|
|
1300
|
+
/**
|
|
1301
|
+
* The processing flags (e.g. `0x0001` for password-based encryption).
|
|
1302
|
+
*/
|
|
1303
|
+
flags?: number;
|
|
1304
|
+
/**
|
|
1305
|
+
* The identifier of the hash algorithm used for the password validation data.
|
|
1306
|
+
*/
|
|
1307
|
+
hashAlgorithm?: number;
|
|
1308
|
+
/**
|
|
1309
|
+
* The password validation data.
|
|
1310
|
+
*/
|
|
1311
|
+
hashData?: Uint8Array;
|
|
1147
1312
|
}
|
|
1148
1313
|
|
|
1149
1314
|
/**
|
|
@@ -2051,6 +2216,19 @@ export interface ZipWriterCloseOptions extends EntryOnprogressOptions {
|
|
|
2051
2216
|
* @defaultValue false
|
|
2052
2217
|
*/
|
|
2053
2218
|
preventClose?: boolean;
|
|
2219
|
+
/**
|
|
2220
|
+
* The function called for signing the central directory. The returned data (e.g. a PKCS#7 signature computed
|
|
2221
|
+
* over the central directory records) is stored in a digital signature record written between the central
|
|
2222
|
+
* directory and the end of central directory record, and exposed by {@link ZipReader#digitalSignature} when
|
|
2223
|
+
* reading the zip file. It must not exceed 64KB, otherwise an {@link ERR_INVALID_SIGNATURE_DATA} error is
|
|
2224
|
+
* thrown. zip.js stores the data as-is and does not implement the signature computation itself.
|
|
2225
|
+
*
|
|
2226
|
+
* @param directory The raw data of the central directory records.
|
|
2227
|
+
* @returns The data of the digital signature record.
|
|
2228
|
+
*/
|
|
2229
|
+
signCentralDirectory?(
|
|
2230
|
+
directory: Uint8Array
|
|
2231
|
+
): Uint8Array | PromiseLike<Uint8Array>;
|
|
2054
2232
|
}
|
|
2055
2233
|
|
|
2056
2234
|
/**
|
|
@@ -3164,3 +3342,56 @@ export const ERR_WRITER_NOT_INITIALIZED: string;
|
|
|
3164
3342
|
* Zip file not empty error
|
|
3165
3343
|
*/
|
|
3166
3344
|
export const ERR_ZIP_NOT_EMPTY: string;
|
|
3345
|
+
/**
|
|
3346
|
+
* Signature data exceeding 64KB error (see {@link ZipWriterCloseOptions#signCentralDirectory})
|
|
3347
|
+
*/
|
|
3348
|
+
export const ERR_INVALID_SIGNATURE_DATA: string;
|
|
3349
|
+
/**
|
|
3350
|
+
* Invalid uid error (thrown when the `uid` option is not an integer in the range 0..2^32-1)
|
|
3351
|
+
*/
|
|
3352
|
+
export const ERR_INVALID_UID: string;
|
|
3353
|
+
/**
|
|
3354
|
+
* Invalid gid error (thrown when the `gid` option is not an integer in the range 0..2^32-1)
|
|
3355
|
+
*/
|
|
3356
|
+
export const ERR_INVALID_GID: string;
|
|
3357
|
+
/**
|
|
3358
|
+
* Invalid UNIX mode error (thrown when the `unixMode` option is not an integer in the range 0..65535)
|
|
3359
|
+
*/
|
|
3360
|
+
export const ERR_INVALID_UNIX_MODE: string;
|
|
3361
|
+
/**
|
|
3362
|
+
* Invalid unixExtraFieldType error (thrown when the `unixExtraFieldType` option is not `"infozip"` or `"unix"`)
|
|
3363
|
+
*/
|
|
3364
|
+
export const ERR_INVALID_UNIX_EXTRA_FIELD_TYPE: string;
|
|
3365
|
+
/**
|
|
3366
|
+
* Invalid UNIX uid/gid size error (thrown when `uid`/`gid` exceeds 65535 with `unixExtraFieldType` set to `"unix"`; use `"infozip"` for larger ids)
|
|
3367
|
+
*/
|
|
3368
|
+
export const ERR_INVALID_UNIX_ID_SIZE: string;
|
|
3369
|
+
/**
|
|
3370
|
+
* Invalid msdosAttributesRaw error (thrown when the `msdosAttributesRaw` option is not an integer in the range 0..255)
|
|
3371
|
+
*/
|
|
3372
|
+
export const ERR_INVALID_MSDOS_ATTRIBUTES: string;
|
|
3373
|
+
/**
|
|
3374
|
+
* Invalid msdosAttributes error (thrown when the `msdosAttributes` option is not an object with boolean flags)
|
|
3375
|
+
*/
|
|
3376
|
+
export const ERR_INVALID_MSDOS_DATA: string;
|
|
3377
|
+
/**
|
|
3378
|
+
* Entry already exists error (thrown by the filesystem API when adding an entry whose filename already exists)
|
|
3379
|
+
*/
|
|
3380
|
+
export const ERR_ENTRY_EXISTS: string;
|
|
3381
|
+
/**
|
|
3382
|
+
* Readable stream already consumed error (thrown by the filesystem API when a readable stream is read more than once)
|
|
3383
|
+
*/
|
|
3384
|
+
export const ERR_READABLE_CONSUMED: string;
|
|
3385
|
+
/**
|
|
3386
|
+
* Unsupported context error (thrown when {@link createSyncAccessHandleTempStream} is used outside a dedicated worker)
|
|
3387
|
+
*/
|
|
3388
|
+
export const ERR_UNSUPPORTED_CONTEXT: string;
|
|
3389
|
+
/**
|
|
3390
|
+
* Unsupported Crypto API error (thrown when writing encrypted entries while `crypto.getRandomValues` is unavailable)
|
|
3391
|
+
*/
|
|
3392
|
+
export const ERR_UNSUPPORTED_CRYPTO_API: string;
|
|
3393
|
+
/**
|
|
3394
|
+
* Web worker startup timeout error (thrown when a web worker does not start in time, e.g. in browser extensions
|
|
3395
|
+
* disallowing workers; set `useWebWorkers` to `false` in {@link configure} to work around it)
|
|
3396
|
+
*/
|
|
3397
|
+
export const ERR_WORKER_STARTUP_TIMEOUT: string;
|
package/index.d.ts
CHANGED
|
@@ -314,6 +314,19 @@ export interface Configuration extends WorkerConfiguration {
|
|
|
314
314
|
* @defaultValue "./core/web-worker.js"
|
|
315
315
|
*/
|
|
316
316
|
workerURI?: string;
|
|
317
|
+
/**
|
|
318
|
+
* The function used to create the web workers, taking precedence over `workerURI`.
|
|
319
|
+
*
|
|
320
|
+
* It lets bundlers detect the worker script statically and compile it with its imports, e.g. a custom worker script embedding alternative compression streams.
|
|
321
|
+
*
|
|
322
|
+
* Here is an example with a custom worker script (see {@link initWorker} for the content of the script):
|
|
323
|
+
* ```
|
|
324
|
+
* configure({
|
|
325
|
+
* createWorker: () => new Worker(new URL("./zip-worker.js", import.meta.url), { type: "module" })
|
|
326
|
+
* });
|
|
327
|
+
* ```
|
|
328
|
+
*/
|
|
329
|
+
createWorker?: () => Worker;
|
|
317
330
|
/**
|
|
318
331
|
* The URI of the WebAssembly module used by default implementations to compress/decompress data. It is ignored if `useCompressionStream` is set to `true` and `CompressionStream`/`DecompressionStream` are supported by the environment.
|
|
319
332
|
*
|
|
@@ -352,12 +365,20 @@ export interface Configuration extends WorkerConfiguration {
|
|
|
352
365
|
*
|
|
353
366
|
* @defaultValue {@link CodecStream}
|
|
354
367
|
*/
|
|
355
|
-
|
|
368
|
+
CompressionStreamFallback?: typeof TransformStreamLike;
|
|
356
369
|
/**
|
|
357
370
|
* The stream implementation used to decompress data when `useCompressionStream` is set to `false`.
|
|
358
371
|
*
|
|
359
372
|
* @defaultValue {@link CodecStream}
|
|
360
373
|
*/
|
|
374
|
+
DecompressionStreamFallback?: typeof TransformStreamLike;
|
|
375
|
+
/**
|
|
376
|
+
* @deprecated Use {@link Configuration#CompressionStreamFallback} instead.
|
|
377
|
+
*/
|
|
378
|
+
CompressionStreamZlib?: typeof TransformStreamLike;
|
|
379
|
+
/**
|
|
380
|
+
* @deprecated Use {@link Configuration#DecompressionStreamFallback} instead.
|
|
381
|
+
*/
|
|
361
382
|
DecompressionStreamZlib?: typeof TransformStreamLike;
|
|
362
383
|
}
|
|
363
384
|
|
|
@@ -390,6 +411,75 @@ export interface WorkerConfiguration {
|
|
|
390
411
|
*/
|
|
391
412
|
export function terminateWorkers(): Promise<void>;
|
|
392
413
|
|
|
414
|
+
/**
|
|
415
|
+
* Initializes a custom web worker script. This function is exposed by the `@zip.js/zip.js/worker` entry point and must be called
|
|
416
|
+
* in the worker script created by {@link Configuration#createWorker} or referenced by {@link Configuration#workerURI}.
|
|
417
|
+
*
|
|
418
|
+
* Here is a complete example of a worker script using fflate as the compression engine, e.g. to reduce the bundle size:
|
|
419
|
+
* ```
|
|
420
|
+
* import { initWorker } from "@zip.js/zip.js/worker";
|
|
421
|
+
* import { Deflate, Inflate } from "fflate";
|
|
422
|
+
*
|
|
423
|
+
* const FORMAT_DEFLATE_RAW = "deflate-raw";
|
|
424
|
+
*
|
|
425
|
+
* class FflateStream extends TransformStream {
|
|
426
|
+
* constructor(codec) {
|
|
427
|
+
* super({
|
|
428
|
+
* start(controller) {
|
|
429
|
+
* codec.ondata = chunk => {
|
|
430
|
+
* if (chunk.length) {
|
|
431
|
+
* controller.enqueue(chunk);
|
|
432
|
+
* }
|
|
433
|
+
* };
|
|
434
|
+
* },
|
|
435
|
+
* transform(chunk) {
|
|
436
|
+
* codec.push(chunk);
|
|
437
|
+
* },
|
|
438
|
+
* flush() {
|
|
439
|
+
* codec.push(new Uint8Array(0), true);
|
|
440
|
+
* }
|
|
441
|
+
* });
|
|
442
|
+
* }
|
|
443
|
+
* }
|
|
444
|
+
*
|
|
445
|
+
* class CompressionStreamFallback extends FflateStream {
|
|
446
|
+
* constructor(format, { level } = {}) {
|
|
447
|
+
* checkFormat(format);
|
|
448
|
+
* super(new Deflate(level === undefined ? {} : { level }));
|
|
449
|
+
* }
|
|
450
|
+
* }
|
|
451
|
+
*
|
|
452
|
+
* class DecompressionStreamFallback extends FflateStream {
|
|
453
|
+
* constructor(format) {
|
|
454
|
+
* checkFormat(format);
|
|
455
|
+
* super(new Inflate());
|
|
456
|
+
* }
|
|
457
|
+
* }
|
|
458
|
+
*
|
|
459
|
+
* function checkFormat(format) {
|
|
460
|
+
* if (format != FORMAT_DEFLATE_RAW) {
|
|
461
|
+
* throw new TypeError("Unsupported compression format: " + format);
|
|
462
|
+
* }
|
|
463
|
+
* }
|
|
464
|
+
*
|
|
465
|
+
* initWorker({ CompressionStreamFallback, DecompressionStreamFallback });
|
|
466
|
+
* ```
|
|
467
|
+
*/
|
|
468
|
+
export function initWorker(options?: {
|
|
469
|
+
/**
|
|
470
|
+
* The stream implementation used to compress data when `useCompressionStream` is set to `false` or when `CompressionStream` is unsupported.
|
|
471
|
+
*/
|
|
472
|
+
CompressionStreamFallback?: typeof TransformStreamLike;
|
|
473
|
+
/**
|
|
474
|
+
* The stream implementation used to decompress data when `useCompressionStream` is set to `false` or when `DecompressionStream` is unsupported.
|
|
475
|
+
*/
|
|
476
|
+
DecompressionStreamFallback?: typeof TransformStreamLike;
|
|
477
|
+
/**
|
|
478
|
+
* The function called before resolving the stream implementations, e.g. to load a WebAssembly module.
|
|
479
|
+
*/
|
|
480
|
+
init?(config: Configuration): Promise<unknown> | unknown;
|
|
481
|
+
}): void;
|
|
482
|
+
|
|
393
483
|
/**
|
|
394
484
|
* Represents a class implementing `CompressionStream` or `DecompressionStream` interfaces.
|
|
395
485
|
*/
|
|
@@ -1029,6 +1119,21 @@ export class ZipReader<Type> {
|
|
|
1029
1119
|
* The data appended after the zip file.
|
|
1030
1120
|
*/
|
|
1031
1121
|
appendedData?: Uint8Array;
|
|
1122
|
+
/**
|
|
1123
|
+
* The data of the digital signature record of the central directory (see
|
|
1124
|
+
* {@link ZipWriterCloseOptions#signCentralDirectory}), if the zip file contains one. zip.js does not verify
|
|
1125
|
+
* signatures; use {@link ZipReader#directoryOffset} and {@link ZipReader#directoryLength} to read the signed
|
|
1126
|
+
* central directory data and verify it.
|
|
1127
|
+
*/
|
|
1128
|
+
digitalSignature?: Uint8Array;
|
|
1129
|
+
/**
|
|
1130
|
+
* The offset of the central directory in the zip file.
|
|
1131
|
+
*/
|
|
1132
|
+
directoryOffset?: number;
|
|
1133
|
+
/**
|
|
1134
|
+
* The length in bytes of the central directory as declared in the end of central directory record.
|
|
1135
|
+
*/
|
|
1136
|
+
directoryLength?: number;
|
|
1032
1137
|
/**
|
|
1033
1138
|
* Returns all the entries in the zip file
|
|
1034
1139
|
*
|
|
@@ -1144,6 +1249,66 @@ export interface GetEntriesOptions {
|
|
|
1144
1249
|
* {@link ERR_AMBIGUOUS_ARCHIVE} error otherwise.
|
|
1145
1250
|
*/
|
|
1146
1251
|
maxAppendedDataSize?: number;
|
|
1252
|
+
/**
|
|
1253
|
+
* The function called for decrypting the central directory when it is encrypted (see the Strong Encryption
|
|
1254
|
+
* Specification in the ZIP format specification). Without this function, reading such an archive throws an
|
|
1255
|
+
* {@link ERR_ENCRYPTED_CENTRAL_DIRECTORY} error. zip.js provides the encrypted data and the related metadata
|
|
1256
|
+
* but does not implement the decryption itself.
|
|
1257
|
+
*
|
|
1258
|
+
* @param data The raw data stored in place of the central directory, i.e. the decryption header followed by
|
|
1259
|
+
* the encrypted (and possibly compressed) central directory, as stored in the zip file.
|
|
1260
|
+
* @param encryptionInfo The encryption metadata read from the Zip64 end of central directory record, or
|
|
1261
|
+
* `undefined` if the zip file does not contain a version 2 record.
|
|
1262
|
+
* @returns The decrypted and decompressed central directory records.
|
|
1263
|
+
*/
|
|
1264
|
+
decryptCentralDirectory?(
|
|
1265
|
+
data: Uint8Array,
|
|
1266
|
+
encryptionInfo?: DirectoryEncryptionInfo
|
|
1267
|
+
): Uint8Array | PromiseLike<Uint8Array>;
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
/**
|
|
1271
|
+
* Represents the encryption metadata of an encrypted central directory (see
|
|
1272
|
+
* {@link GetEntriesOptions#decryptCentralDirectory}), read from the version 2 Zip64 end of central directory
|
|
1273
|
+
* record.
|
|
1274
|
+
*/
|
|
1275
|
+
export interface DirectoryEncryptionInfo {
|
|
1276
|
+
/**
|
|
1277
|
+
* The raw data of the extensible data sector of the record.
|
|
1278
|
+
*/
|
|
1279
|
+
rawExtensibleData: Uint8Array;
|
|
1280
|
+
/**
|
|
1281
|
+
* The compression method applied to the central directory before encryption.
|
|
1282
|
+
*/
|
|
1283
|
+
compressionMethod?: number;
|
|
1284
|
+
/**
|
|
1285
|
+
* The size of the compressed and encrypted central directory.
|
|
1286
|
+
*/
|
|
1287
|
+
compressedSize?: number;
|
|
1288
|
+
/**
|
|
1289
|
+
* The size of the central directory once decrypted and decompressed.
|
|
1290
|
+
*/
|
|
1291
|
+
uncompressedSize?: number;
|
|
1292
|
+
/**
|
|
1293
|
+
* The identifier of the encryption algorithm (e.g. `0x6610` for AES-256).
|
|
1294
|
+
*/
|
|
1295
|
+
encryptionAlgorithm?: number;
|
|
1296
|
+
/**
|
|
1297
|
+
* The key size in bits.
|
|
1298
|
+
*/
|
|
1299
|
+
bitLength?: number;
|
|
1300
|
+
/**
|
|
1301
|
+
* The processing flags (e.g. `0x0001` for password-based encryption).
|
|
1302
|
+
*/
|
|
1303
|
+
flags?: number;
|
|
1304
|
+
/**
|
|
1305
|
+
* The identifier of the hash algorithm used for the password validation data.
|
|
1306
|
+
*/
|
|
1307
|
+
hashAlgorithm?: number;
|
|
1308
|
+
/**
|
|
1309
|
+
* The password validation data.
|
|
1310
|
+
*/
|
|
1311
|
+
hashData?: Uint8Array;
|
|
1147
1312
|
}
|
|
1148
1313
|
|
|
1149
1314
|
/**
|
|
@@ -2051,6 +2216,19 @@ export interface ZipWriterCloseOptions extends EntryOnprogressOptions {
|
|
|
2051
2216
|
* @defaultValue false
|
|
2052
2217
|
*/
|
|
2053
2218
|
preventClose?: boolean;
|
|
2219
|
+
/**
|
|
2220
|
+
* The function called for signing the central directory. The returned data (e.g. a PKCS#7 signature computed
|
|
2221
|
+
* over the central directory records) is stored in a digital signature record written between the central
|
|
2222
|
+
* directory and the end of central directory record, and exposed by {@link ZipReader#digitalSignature} when
|
|
2223
|
+
* reading the zip file. It must not exceed 64KB, otherwise an {@link ERR_INVALID_SIGNATURE_DATA} error is
|
|
2224
|
+
* thrown. zip.js stores the data as-is and does not implement the signature computation itself.
|
|
2225
|
+
*
|
|
2226
|
+
* @param directory The raw data of the central directory records.
|
|
2227
|
+
* @returns The data of the digital signature record.
|
|
2228
|
+
*/
|
|
2229
|
+
signCentralDirectory?(
|
|
2230
|
+
directory: Uint8Array
|
|
2231
|
+
): Uint8Array | PromiseLike<Uint8Array>;
|
|
2054
2232
|
}
|
|
2055
2233
|
|
|
2056
2234
|
/**
|
|
@@ -3164,3 +3342,56 @@ export const ERR_WRITER_NOT_INITIALIZED: string;
|
|
|
3164
3342
|
* Zip file not empty error
|
|
3165
3343
|
*/
|
|
3166
3344
|
export const ERR_ZIP_NOT_EMPTY: string;
|
|
3345
|
+
/**
|
|
3346
|
+
* Signature data exceeding 64KB error (see {@link ZipWriterCloseOptions#signCentralDirectory})
|
|
3347
|
+
*/
|
|
3348
|
+
export const ERR_INVALID_SIGNATURE_DATA: string;
|
|
3349
|
+
/**
|
|
3350
|
+
* Invalid uid error (thrown when the `uid` option is not an integer in the range 0..2^32-1)
|
|
3351
|
+
*/
|
|
3352
|
+
export const ERR_INVALID_UID: string;
|
|
3353
|
+
/**
|
|
3354
|
+
* Invalid gid error (thrown when the `gid` option is not an integer in the range 0..2^32-1)
|
|
3355
|
+
*/
|
|
3356
|
+
export const ERR_INVALID_GID: string;
|
|
3357
|
+
/**
|
|
3358
|
+
* Invalid UNIX mode error (thrown when the `unixMode` option is not an integer in the range 0..65535)
|
|
3359
|
+
*/
|
|
3360
|
+
export const ERR_INVALID_UNIX_MODE: string;
|
|
3361
|
+
/**
|
|
3362
|
+
* Invalid unixExtraFieldType error (thrown when the `unixExtraFieldType` option is not `"infozip"` or `"unix"`)
|
|
3363
|
+
*/
|
|
3364
|
+
export const ERR_INVALID_UNIX_EXTRA_FIELD_TYPE: string;
|
|
3365
|
+
/**
|
|
3366
|
+
* Invalid UNIX uid/gid size error (thrown when `uid`/`gid` exceeds 65535 with `unixExtraFieldType` set to `"unix"`; use `"infozip"` for larger ids)
|
|
3367
|
+
*/
|
|
3368
|
+
export const ERR_INVALID_UNIX_ID_SIZE: string;
|
|
3369
|
+
/**
|
|
3370
|
+
* Invalid msdosAttributesRaw error (thrown when the `msdosAttributesRaw` option is not an integer in the range 0..255)
|
|
3371
|
+
*/
|
|
3372
|
+
export const ERR_INVALID_MSDOS_ATTRIBUTES: string;
|
|
3373
|
+
/**
|
|
3374
|
+
* Invalid msdosAttributes error (thrown when the `msdosAttributes` option is not an object with boolean flags)
|
|
3375
|
+
*/
|
|
3376
|
+
export const ERR_INVALID_MSDOS_DATA: string;
|
|
3377
|
+
/**
|
|
3378
|
+
* Entry already exists error (thrown by the filesystem API when adding an entry whose filename already exists)
|
|
3379
|
+
*/
|
|
3380
|
+
export const ERR_ENTRY_EXISTS: string;
|
|
3381
|
+
/**
|
|
3382
|
+
* Readable stream already consumed error (thrown by the filesystem API when a readable stream is read more than once)
|
|
3383
|
+
*/
|
|
3384
|
+
export const ERR_READABLE_CONSUMED: string;
|
|
3385
|
+
/**
|
|
3386
|
+
* Unsupported context error (thrown when {@link createSyncAccessHandleTempStream} is used outside a dedicated worker)
|
|
3387
|
+
*/
|
|
3388
|
+
export const ERR_UNSUPPORTED_CONTEXT: string;
|
|
3389
|
+
/**
|
|
3390
|
+
* Unsupported Crypto API error (thrown when writing encrypted entries while `crypto.getRandomValues` is unavailable)
|
|
3391
|
+
*/
|
|
3392
|
+
export const ERR_UNSUPPORTED_CRYPTO_API: string;
|
|
3393
|
+
/**
|
|
3394
|
+
* Web worker startup timeout error (thrown when a web worker does not start in time, e.g. in browser extensions
|
|
3395
|
+
* disallowing workers; set `useWebWorkers` to `false` in {@link configure} to work around it)
|
|
3396
|
+
*/
|
|
3397
|
+
export const ERR_WORKER_STARTUP_TIMEOUT: string;
|