@zip.js/zip.js 2.8.29 → 2.8.30
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/BENCHMARKS.md +35 -0
- package/deno.json +1 -1
- package/dist/zip-core.js +527 -48
- package/dist/zip-core.min.js +1 -1
- package/dist/zip-fs-core.js +413 -48
- package/dist/zip-fs-core.min.js +1 -1
- package/dist/zip-fs-native.js +589 -52
- package/dist/zip-fs-native.min.js +1 -1
- package/dist/zip-fs.js +587 -50
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-legacy.js +528 -49
- package/dist/zip-legacy.min.js +1 -1
- package/dist/zip-module.wasm +0 -0
- package/dist/zip-native.js +531 -52
- 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 +529 -50
- package/dist/zip.min.js +1 -1
- package/index-native.cjs +589 -52
- package/index-native.min.js +1 -1
- package/index.cjs +587 -50
- package/index.d.ts +126 -1
- package/index.min.js +1 -1
- package/lib/core/options.js +11 -1
- package/lib/core/streams/codecs/crc32.js +39 -11
- package/lib/core/streams/zip-entry-stream.js +85 -5
- package/lib/core/streams/zlib-js/zlib-streams.min.js +1 -1
- package/lib/core/streams/zlib-wasm/zlib-streams.wasm +0 -0
- package/lib/core/util/opfs-temp-stream.js +175 -0
- package/lib/core/web-worker-inline-native.js +1 -1
- package/lib/core/web-worker-inline-wasm.js +1 -1
- package/lib/core/zip-fs.js +58 -0
- package/lib/core/zip-reader.js +219 -31
- package/lib/core/zip-writer.js +11 -0
- package/lib/core/zlib-streams-inline.js +1 -1
- package/lib/zip-core-base.js +4 -1
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -327,6 +327,60 @@ declare class CodecStream extends TransformStream {}
|
|
|
327
327
|
*/
|
|
328
328
|
export function getMimeType(fileExtension: string): string;
|
|
329
329
|
|
|
330
|
+
/**
|
|
331
|
+
* A `TransformStream`-like temporary buffer returned by a {@link ZipWriterConstructorOptions.createTempStream} factory.
|
|
332
|
+
*/
|
|
333
|
+
export interface TempStream {
|
|
334
|
+
/**
|
|
335
|
+
* The writable side, receiving the compressed data of a buffered entry.
|
|
336
|
+
*/
|
|
337
|
+
writable: WritableStream;
|
|
338
|
+
/**
|
|
339
|
+
* The readable side, replayed into the final zip stream once the entry is ready.
|
|
340
|
+
*/
|
|
341
|
+
readable: ReadableStream;
|
|
342
|
+
/**
|
|
343
|
+
* Optional cleanup, called once the entry has been processed (on success, error, or abort) to release any backing resource.
|
|
344
|
+
*/
|
|
345
|
+
dispose?: () => void | Promise<void>;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Options for {@link createOPFSTempStream}.
|
|
350
|
+
*/
|
|
351
|
+
export interface OPFSTempStreamOptions {
|
|
352
|
+
/**
|
|
353
|
+
* Spill a buffered entry to a file once its buffered data exceeds this size, in bytes. Smaller entries stay in memory.
|
|
354
|
+
*
|
|
355
|
+
* @defaultValue 1048576
|
|
356
|
+
*/
|
|
357
|
+
thresholdBytes?: number;
|
|
358
|
+
/**
|
|
359
|
+
* Name of the OPFS sub-directory holding the temporary files.
|
|
360
|
+
*
|
|
361
|
+
* @defaultValue ".zip.js-temp"
|
|
362
|
+
*/
|
|
363
|
+
directoryName?: string;
|
|
364
|
+
/**
|
|
365
|
+
* Returns (or resolves to) the root `FileSystemDirectoryHandle`. Defaults to `navigator.storage.getDirectory()`.
|
|
366
|
+
*
|
|
367
|
+
* Provide it to run inside a worker with a pre-obtained handle, or to test against a mock.
|
|
368
|
+
*/
|
|
369
|
+
getDirectory?: () => FileSystemDirectoryHandle | Promise<FileSystemDirectoryHandle>;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Builds a {@link ZipWriterConstructorOptions.createTempStream} factory that spills the data of buffered entries to the Origin Private File System (OPFS) instead of keeping it in memory.
|
|
374
|
+
*
|
|
375
|
+
* An entry stays in memory until it exceeds `thresholdBytes`, then spills to a temporary OPFS file that is streamed back and deleted afterwards, so peak memory stays bounded on large buffered entries.
|
|
376
|
+
*
|
|
377
|
+
* OPFS is a browser/worker feature; feature-detect `navigator.storage.getDirectory` (or pass `getDirectory`) before using it, and let the writer use its in-memory default elsewhere.
|
|
378
|
+
*
|
|
379
|
+
* @param options The options.
|
|
380
|
+
* @returns A factory suitable for {@link ZipWriterConstructorOptions.createTempStream}.
|
|
381
|
+
*/
|
|
382
|
+
export function createOPFSTempStream(options?: OPFSTempStreamOptions): () => Promise<TempStream>;
|
|
383
|
+
|
|
330
384
|
/**
|
|
331
385
|
* Represents an instance used to read or write unknown type of data.
|
|
332
386
|
*
|
|
@@ -861,12 +915,55 @@ export interface GetEntriesOptions {
|
|
|
861
915
|
* @defaultValue false
|
|
862
916
|
*/
|
|
863
917
|
checkAmbiguity?: boolean;
|
|
918
|
+
/**
|
|
919
|
+
* How tolerant the reader should be when the archive can be parsed in more than one way.
|
|
920
|
+
*
|
|
921
|
+
* - `"strict"`: reject anything another tool could interpret differently. The end of central directory
|
|
922
|
+
* record must sit exactly at the end of the file, no data may precede the zip structure, and the local file
|
|
923
|
+
* headers must agree with the central directory records. Equivalent to {@link GetEntriesOptions#checkAmbiguity}
|
|
924
|
+
* set to `true`.
|
|
925
|
+
* - `"balanced"`: select the last end of central directory record whose comment reaches the end of the file
|
|
926
|
+
* and that points to a central directory, ignore stale records left by in-place updates as well as records
|
|
927
|
+
* forged inside a comment, and tolerate a self-extracting stub or up to
|
|
928
|
+
* {@link GetEntriesOptions#maxAppendedDataSize} bytes of appended data. Throw an {@link ERR_AMBIGUOUS_ARCHIVE}
|
|
929
|
+
* error only when two or more records reach the end of the file and each points to a central directory, which
|
|
930
|
+
* cannot be disambiguated. A record that reaches the end of the file but points to no central directory (an
|
|
931
|
+
* empty archive) is only selected when no record points to one.
|
|
932
|
+
* - `"tolerant"`: never reject a parseable archive, except when {@link GetEntriesOptions#maxAppendedDataSize}
|
|
933
|
+
* is set explicitly and exceeded; recover by selecting the last end of central directory record that reaches
|
|
934
|
+
* the end of the file and points to a central directory (or, failing that, the last one that reaches the end
|
|
935
|
+
* of the file).
|
|
936
|
+
*
|
|
937
|
+
* @defaultValue "balanced"
|
|
938
|
+
*/
|
|
939
|
+
strictness?: "strict" | "balanced" | "tolerant";
|
|
940
|
+
/**
|
|
941
|
+
* The maximum number of bytes tolerated after the zip structure before the archive is rejected. Defaults to
|
|
942
|
+
* `0` when {@link GetEntriesOptions#strictness} is `"strict"`, `65535` when it is `"balanced"`, and `Infinity`
|
|
943
|
+
* when it is `"tolerant"`.
|
|
944
|
+
*
|
|
945
|
+
* An explicit value takes precedence over the strictness default at every level, so it can loosen `"strict"`
|
|
946
|
+
* or reintroduce a rejection under `"tolerant"`. It also bounds how far back the end of central directory
|
|
947
|
+
* record is searched for, so a value smaller than the amount of data actually appended surfaces an
|
|
948
|
+
* {@link ERR_EOCDR_NOT_FOUND} error when the record lies beyond the searched region and an
|
|
949
|
+
* {@link ERR_AMBIGUOUS_ARCHIVE} error otherwise.
|
|
950
|
+
*/
|
|
951
|
+
maxAppendedDataSize?: number;
|
|
864
952
|
}
|
|
865
953
|
|
|
866
954
|
/**
|
|
867
955
|
* Represents options passed to the constructor of {@link ZipReader} and {@link FileEntry#getData}.
|
|
868
956
|
*/
|
|
869
957
|
export interface ZipReaderOptions {
|
|
958
|
+
/**
|
|
959
|
+
* How tolerant the reader should be when the local file header of an entry disagrees with its central
|
|
960
|
+
* directory record. `"strict"` throws an {@link ERR_AMBIGUOUS_ARCHIVE} error (equivalent to
|
|
961
|
+
* {@link ZipReaderOptions#checkAmbiguity} set to `true`); `"balanced"` and `"tolerant"` trust the central
|
|
962
|
+
* directory record.
|
|
963
|
+
*
|
|
964
|
+
* @defaultValue "balanced"
|
|
965
|
+
*/
|
|
966
|
+
strictness?: "strict" | "balanced" | "tolerant";
|
|
870
967
|
/**
|
|
871
968
|
* `true` to throw an {@link ERR_AMBIGUOUS_ARCHIVE} error when calling {@link FileEntry#getData} if the local
|
|
872
969
|
* file header of the entry disagrees with its central directory record in a way that could make other tools
|
|
@@ -1486,8 +1583,11 @@ export interface ZipWriterConstructorOptions extends WorkerConfiguration {
|
|
|
1486
1583
|
*
|
|
1487
1584
|
* When provided, this replaces the default in-memory `TransformStream` buffer, allowing data to be stored externally (e.g. filesystem, OPFS, network).
|
|
1488
1585
|
* The `writable` side receives compressed entry data. The `readable` side is consumed when the entry is replayed into the final zip stream.
|
|
1586
|
+
* 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
|
+
*
|
|
1588
|
+
* See {@link createOPFSTempStream} for a ready-made OPFS-backed implementation.
|
|
1489
1589
|
*/
|
|
1490
|
-
createTempStream?: () => Promise<
|
|
1590
|
+
createTempStream?: () => TempStream | Promise<TempStream>;
|
|
1491
1591
|
/**
|
|
1492
1592
|
* `true` to keep the order of the entry physically in the zip file.
|
|
1493
1593
|
*
|
|
@@ -2165,6 +2265,17 @@ export class ZipDirectoryEntry extends ZipEntry {
|
|
|
2165
2265
|
writable?: WritableStream,
|
|
2166
2266
|
options?: ZipDirectoryEntryExportOptions
|
|
2167
2267
|
): Promise<WritableStream>;
|
|
2268
|
+
/**
|
|
2269
|
+
* Writes the entry and its descendants into a directory as files and sub-directories via the File System Access API (e.g. the Origin Private File System). Files are streamed and directories are merged into the target; colliding files are overwritten. This is the inverse of {@link ZipDirectoryEntry#addFileSystemHandle}.
|
|
2270
|
+
*
|
|
2271
|
+
* @param directoryHandle The target `FileSystemDirectoryHandle` instance.
|
|
2272
|
+
* @param options The options.
|
|
2273
|
+
* @returns A promise resolving to the target `FileSystemDirectoryHandle` instance.
|
|
2274
|
+
*/
|
|
2275
|
+
exportFileSystemHandle(
|
|
2276
|
+
directoryHandle: FileSystemDirectoryHandle,
|
|
2277
|
+
options?: ZipDirectoryEntryExportFileSystemHandleOptions
|
|
2278
|
+
): Promise<FileSystemDirectoryHandle>;
|
|
2168
2279
|
/**
|
|
2169
2280
|
* Creates a zip file via a custom {@link Writer} instance containing the entry and its descendants
|
|
2170
2281
|
*
|
|
@@ -2209,6 +2320,19 @@ export interface ZipDirectoryEntryExportOptions
|
|
|
2209
2320
|
readerOptions?: ZipReaderConstructorOptions;
|
|
2210
2321
|
}
|
|
2211
2322
|
|
|
2323
|
+
/**
|
|
2324
|
+
* Represents the options passed to {@link ZipDirectoryEntry#exportFileSystemHandle} and {@link FS#exportFileSystemHandle}.
|
|
2325
|
+
*/
|
|
2326
|
+
export interface ZipDirectoryEntryExportFileSystemHandleOptions
|
|
2327
|
+
extends EntryGetDataOptions {
|
|
2328
|
+
/**
|
|
2329
|
+
* `true` to write independent files concurrently instead of one after another.
|
|
2330
|
+
*
|
|
2331
|
+
* @defaultValue false
|
|
2332
|
+
*/
|
|
2333
|
+
concurrent?: boolean;
|
|
2334
|
+
}
|
|
2335
|
+
|
|
2212
2336
|
/**
|
|
2213
2337
|
* Represents a Filesystem instance.
|
|
2214
2338
|
*
|
|
@@ -2251,6 +2375,7 @@ export interface FS
|
|
|
2251
2375
|
| "exportData64URI"
|
|
2252
2376
|
| "exportUint8Array"
|
|
2253
2377
|
| "exportWritable"
|
|
2378
|
+
| "exportFileSystemHandle"
|
|
2254
2379
|
| "exportZip"
|
|
2255
2380
|
| "isPasswordProtected"
|
|
2256
2381
|
| "checkPassword"
|