@zip.js/zip.js 2.8.49 → 2.8.50
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/deno.json +1 -1
- package/dist/zip-core-external.js +333 -203
- package/dist/zip-core-external.min.js +1 -1
- package/dist/zip-core.js +339 -203
- package/dist/zip-core.min.js +1 -1
- package/dist/zip-fs-core-external.js +420 -214
- package/dist/zip-fs-core-external.min.js +1 -1
- package/dist/zip-fs-core.js +212 -450
- package/dist/zip-fs-core.min.js +1 -1
- package/dist/zip-fs-external.js +420 -214
- package/dist/zip-fs-external.min.js +1 -1
- package/dist/zip-fs-native.js +426 -214
- package/dist/zip-fs-native.min.js +1 -1
- package/dist/zip-fs.js +426 -214
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-legacy.js +339 -203
- package/dist/zip-legacy.min.js +1 -1
- package/dist/zip-native.js +339 -203
- package/dist/zip-native.min.js +1 -1
- package/dist/zip.js +339 -203
- package/dist/zip.min.js +1 -1
- package/index-native.cjs +425 -213
- package/index-native.min.js +1 -1
- package/index.cjs +425 -213
- package/index.d.cts +124 -2
- package/index.d.ts +124 -2
- package/index.min.js +1 -1
- package/lib/core/codec-registry.js +2 -2
- package/lib/core/codec-worker-web.js +436 -0
- package/lib/core/codec-worker.js +23 -404
- package/lib/core/constants.js +5 -1
- package/lib/core/io.js +2 -1
- package/lib/core/options.js +8 -0
- package/lib/core/zip-fs.js +88 -12
- package/lib/core/zip-reader.js +90 -16
- package/lib/core/zip-writer.js +36 -13
- package/lib/zip-core-reader.js +6 -0
- package/lib/zip-core-writer.js +4 -0
- package/package.json +1 -1
package/index.d.cts
CHANGED
|
@@ -1201,9 +1201,10 @@ export interface GetEntriesOptions {
|
|
|
1201
1201
|
*
|
|
1202
1202
|
* @param value The raw text value.
|
|
1203
1203
|
* @param encoding The encoding of the text.
|
|
1204
|
+
* @param type The type of the decoded text, `"filename"` or `"comment"`.
|
|
1204
1205
|
* @returns The decoded text value or `undefined` if the raw text value should be decoded by zip.js.
|
|
1205
1206
|
*/
|
|
1206
|
-
decodeText?(value: Uint8Array, encoding: string): string | undefined;
|
|
1207
|
+
decodeText?(value: Uint8Array, encoding: string, type: "filename" | "comment"): string | undefined;
|
|
1207
1208
|
/**
|
|
1208
1209
|
* `true` to throw an {@link ERR_AMBIGUOUS_ARCHIVE} error when the archive could be parsed differently by other
|
|
1209
1210
|
* tools. This detects data before or after the zip structure (e.g. a self-extracting archive stub or a
|
|
@@ -1237,6 +1238,42 @@ export interface GetEntriesOptions {
|
|
|
1237
1238
|
* @defaultValue "balanced"
|
|
1238
1239
|
*/
|
|
1239
1240
|
strictness?: "strict" | "balanced" | "tolerant";
|
|
1241
|
+
/**
|
|
1242
|
+
* How strictly the filename of each entry should be validated. A rejected name throws an
|
|
1243
|
+
* {@link ERR_UNSAFE_FILENAME} error carrying the offending name in its `filename` property.
|
|
1244
|
+
*
|
|
1245
|
+
* - `"strict"`: reject the names rejected by `"balanced"`, plus the names that do not map cleanly to a file
|
|
1246
|
+
* path, i.e. empty names and names containing a `"."` path component or an empty one (e.g. `"a//b.txt"`).
|
|
1247
|
+
* - `"balanced"`: reject names that would escape the directory they are extracted into, i.e. names containing
|
|
1248
|
+
* a `".."` path component, and absolute names, i.e. names starting with `"/"`, with a drive letter (e.g.
|
|
1249
|
+
* `"C:/file.txt"`) or with two backslashes (UNC paths).
|
|
1250
|
+
* - `"tolerant"`: never reject a name.
|
|
1251
|
+
*
|
|
1252
|
+
* A backslash is never interpreted as a path separator: it is a valid filename character on UNIX systems, and
|
|
1253
|
+
* it also occurs as the trail byte of legitimate double-byte filenames (e.g. CP932) decoded with another
|
|
1254
|
+
* charset.
|
|
1255
|
+
*
|
|
1256
|
+
* Names are validated, never rewritten, so the filename reported for an entry always matches its central
|
|
1257
|
+
* directory record.
|
|
1258
|
+
*
|
|
1259
|
+
* @defaultValue The value of {@link GetEntriesOptions#strictness}.
|
|
1260
|
+
*/
|
|
1261
|
+
filenameValidation?: "strict" | "balanced" | "tolerant";
|
|
1262
|
+
/**
|
|
1263
|
+
* The function called for normalizing the filename of each entry, e.g. to repair the names rejected by
|
|
1264
|
+
* {@link GetEntriesOptions#filenameValidation}.
|
|
1265
|
+
*
|
|
1266
|
+
* It is called with the decoded filename, after {@link GetEntriesOptions#decodeText} and before the name is
|
|
1267
|
+
* validated, so a name it fails to repair is still rejected. The returned name becomes the name of the entry:
|
|
1268
|
+
* it is used to detect directory entries by their trailing `"/"`, and to detect duplicate filenames when
|
|
1269
|
+
* {@link GetEntriesOptions#checkAmbiguity} is set, so two names normalized into the same name are reported as
|
|
1270
|
+
* an {@link ERR_AMBIGUOUS_ARCHIVE} error instead of silently shadowing each other. The raw filename remains
|
|
1271
|
+
* available in {@link EntryMetaData#rawFilename}.
|
|
1272
|
+
*
|
|
1273
|
+
* @param filename The decoded filename.
|
|
1274
|
+
* @returns The normalized filename or `undefined` to keep the decoded filename.
|
|
1275
|
+
*/
|
|
1276
|
+
normalizeFilename?(filename: string): string | undefined;
|
|
1240
1277
|
/**
|
|
1241
1278
|
* The maximum number of bytes tolerated after the zip structure before the archive is rejected. Defaults to
|
|
1242
1279
|
* `0` when {@link GetEntriesOptions#strictness} is `"strict"`, `65535` when it is `"balanced"`, and `Infinity`
|
|
@@ -1613,6 +1650,27 @@ export interface EntryError extends Error {
|
|
|
1613
1650
|
* The id of the related {@link ZipEntry} (filesystem API).
|
|
1614
1651
|
*/
|
|
1615
1652
|
entryId?: number;
|
|
1653
|
+
/**
|
|
1654
|
+
* The name of the related {@link ZipEntry}, or of the related `FileSystemHandle` when importing
|
|
1655
|
+
* one (filesystem API). Set by {@link ZipDirectoryEntry#addFileSystemHandle} and
|
|
1656
|
+
* {@link ZipDirectoryEntry#exportFileSystemHandle}, which rethrow the original error rather than
|
|
1657
|
+
* wrapping it, so its `message` stays comparable to the exported `ERR_*` constants.
|
|
1658
|
+
*/
|
|
1659
|
+
entryName?: string;
|
|
1660
|
+
/**
|
|
1661
|
+
* The other entries that also failed, when {@link ZipDirectoryEntry#exportFileSystemHandle} runs
|
|
1662
|
+
* with `concurrent` set to `true` and more than one entry fails (filesystem API). The error it is
|
|
1663
|
+
* set on is not repeated in the list, and failures raised deeper in the tree are flattened into
|
|
1664
|
+
* it, so the list holds every failure of the export except this one.
|
|
1665
|
+
*/
|
|
1666
|
+
entryErrors?: EntryError[];
|
|
1667
|
+
/**
|
|
1668
|
+
* The names of the files {@link ZipDirectoryEntry#exportFileSystemHandle} finished writing before
|
|
1669
|
+
* it failed, relative to the exported entry (filesystem API). Directories are not listed. Every
|
|
1670
|
+
* other file of the export is either missing or empty, so this is the only way to tell a file the
|
|
1671
|
+
* export completed from one it created but never filled.
|
|
1672
|
+
*/
|
|
1673
|
+
exportedEntryNames?: string[];
|
|
1616
1674
|
}
|
|
1617
1675
|
/**
|
|
1618
1676
|
* Represents the metadata of an entry in a zip file (Core API).
|
|
@@ -2497,9 +2555,10 @@ export interface ZipWriterConstructorOptions extends WorkerConfiguration {
|
|
|
2497
2555
|
* The function called for encoding the filename and the comment of the entry.
|
|
2498
2556
|
*
|
|
2499
2557
|
* @param text The text to encode.
|
|
2558
|
+
* @param type The type of the encoded text, `"filename"` or `"comment"`.
|
|
2500
2559
|
* @returns The encoded text or `undefined` if the text should be encoded by zip.js.
|
|
2501
2560
|
*/
|
|
2502
|
-
encodeText?(text: string): Uint8Array | undefined;
|
|
2561
|
+
encodeText?(text: string, type: "filename" | "comment"): Uint8Array | undefined;
|
|
2503
2562
|
}
|
|
2504
2563
|
|
|
2505
2564
|
/**
|
|
@@ -2867,6 +2926,10 @@ export class ZipDirectoryEntry extends ZipEntry {
|
|
|
2867
2926
|
/**
|
|
2868
2927
|
* Adds an entry with content provided via a `FileSystemHandle` instance
|
|
2869
2928
|
*
|
|
2929
|
+
* If a handle cannot be read, the original error is rethrown unmodified as an {@link EntryError},
|
|
2930
|
+
* whose {@link EntryError#entryName} is the path of the handle that failed, relative to the parent
|
|
2931
|
+
* of `fileSystemHandle`.
|
|
2932
|
+
*
|
|
2870
2933
|
* @param fileSystemHandle The `fileSystemHandle` instance.
|
|
2871
2934
|
* @param options The options.
|
|
2872
2935
|
* @returns A promise resolving to an array of {@link ZipFileEntry} or a {@link ZipDirectoryEntry} instances.
|
|
@@ -2930,6 +2993,11 @@ export class ZipDirectoryEntry extends ZipEntry {
|
|
|
2930
2993
|
*
|
|
2931
2994
|
* @param reader The {@link Reader} instance.
|
|
2932
2995
|
* @param options The options.
|
|
2996
|
+
*
|
|
2997
|
+
* @remarks The filename of each entry is split into path components to build the tree of entries. Empty
|
|
2998
|
+
* components and `"."` components are ignored, so `"a//b.txt"`, `"./a/b.txt"` and `"a/./b.txt"` all produce
|
|
2999
|
+
* the same `"a/b.txt"` entry. Filenames are normalized and validated beforehand, see
|
|
3000
|
+
* {@link GetEntriesOptions#normalizeFilename} and {@link GetEntriesOptions#filenameValidation}.
|
|
2933
3001
|
*/
|
|
2934
3002
|
importZip(
|
|
2935
3003
|
reader:
|
|
@@ -2978,6 +3046,24 @@ export class ZipDirectoryEntry extends ZipEntry {
|
|
|
2978
3046
|
/**
|
|
2979
3047
|
* 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}.
|
|
2980
3048
|
*
|
|
3049
|
+
* If an entry cannot be written, the original error is rethrown unmodified as an {@link EntryError},
|
|
3050
|
+
* whose {@link EntryError#entryName} is the name of the entry that failed, relative to this entry.
|
|
3051
|
+
*
|
|
3052
|
+
* The export is not atomic and nothing is rolled back, because the target is merged into rather
|
|
3053
|
+
* than replaced: a file that already existed cannot be restored once overwritten. On failure the
|
|
3054
|
+
* target is left as follows, and {@link EntryError#exportedEntryNames} lists the files that
|
|
3055
|
+
* completed:
|
|
3056
|
+
* - files written before the failure are left in place, complete and valid;
|
|
3057
|
+
* - a file whose write started but did not finish is left empty, because it is created before its
|
|
3058
|
+
* content is streamed; this includes the entry that failed and, with `concurrent`, every entry
|
|
3059
|
+
* cancelled alongside it;
|
|
3060
|
+
* - files that already existed in the target keep their previous content unless they were
|
|
3061
|
+
* overwritten in full;
|
|
3062
|
+
* - entries not started yet are missing, as are the directories that would have held them.
|
|
3063
|
+
*
|
|
3064
|
+
* Running the same export again is the supported way to recover, since directories are merged and
|
|
3065
|
+
* files are overwritten.
|
|
3066
|
+
*
|
|
2981
3067
|
* @param directoryHandle The target `FileSystemDirectoryHandle` instance.
|
|
2982
3068
|
* @param options The options.
|
|
2983
3069
|
* @returns A promise resolving to the target `FileSystemDirectoryHandle` instance.
|
|
@@ -3038,6 +3124,11 @@ export interface ZipDirectoryEntryExportFileSystemHandleOptions
|
|
|
3038
3124
|
/**
|
|
3039
3125
|
* `true` to write independent files concurrently instead of one after another.
|
|
3040
3126
|
*
|
|
3127
|
+
* When an entry fails, the entries still in flight are cancelled and the ones not started yet are
|
|
3128
|
+
* skipped, so a failed export stops as early as it does when writing one file after another. An
|
|
3129
|
+
* entry whose write has already been requested may still be created, because the File System
|
|
3130
|
+
* Access API cannot cancel a pending `getFileHandle` or `getDirectoryHandle` call.
|
|
3131
|
+
*
|
|
3041
3132
|
* @defaultValue false
|
|
3042
3133
|
*/
|
|
3043
3134
|
concurrent?: boolean;
|
|
@@ -3322,6 +3413,26 @@ export const ERR_AMBIGUOUS_ARCHIVE: string;
|
|
|
3322
3413
|
* Encryption Specification, which is not supported.
|
|
3323
3414
|
*/
|
|
3324
3415
|
export const ERR_ENCRYPTED_CENTRAL_DIRECTORY: string;
|
|
3416
|
+
/**
|
|
3417
|
+
* Unsafe filename error
|
|
3418
|
+
*
|
|
3419
|
+
* @remarks Thrown when reading an archive containing an entry whose filename is rejected by
|
|
3420
|
+
* {@link GetEntriesOptions#filenameValidation}. The thrown error carries the offending name in its `filename`
|
|
3421
|
+
* property.
|
|
3422
|
+
*/
|
|
3423
|
+
export const ERR_UNSAFE_FILENAME: string;
|
|
3424
|
+
/**
|
|
3425
|
+
* Invalid strictness error (thrown when the `strictness` option is not `"strict"`, `"balanced"` or `"tolerant"`)
|
|
3426
|
+
*/
|
|
3427
|
+
export const ERR_INVALID_STRICTNESS: string;
|
|
3428
|
+
/**
|
|
3429
|
+
* Invalid filenameValidation error (thrown when the `filenameValidation` option is not `"strict"`, `"balanced"` or `"tolerant"`)
|
|
3430
|
+
*/
|
|
3431
|
+
export const ERR_INVALID_FILENAME_VALIDATION: string;
|
|
3432
|
+
/**
|
|
3433
|
+
* Invalid maxAppendedDataSize error (thrown when the `maxAppendedDataSize` option is not a number greater than or equal to 0)
|
|
3434
|
+
*/
|
|
3435
|
+
export const ERR_INVALID_MAX_APPENDED_DATA_SIZE: string;
|
|
3325
3436
|
/**
|
|
3326
3437
|
* Iteration completed too soon error
|
|
3327
3438
|
*/
|
|
@@ -3374,6 +3485,17 @@ export const ERR_INVALID_MSDOS_ATTRIBUTES: string;
|
|
|
3374
3485
|
* Invalid msdosAttributes error (thrown when the `msdosAttributes` option is not an object with boolean flags)
|
|
3375
3486
|
*/
|
|
3376
3487
|
export const ERR_INVALID_MSDOS_DATA: string;
|
|
3488
|
+
/**
|
|
3489
|
+
* Invalid level error (thrown when the `level` option is not an integer in the range 0..9)
|
|
3490
|
+
*/
|
|
3491
|
+
export const ERR_INVALID_LEVEL: string;
|
|
3492
|
+
/**
|
|
3493
|
+
* Invalid password error (thrown when the `password` option is not a string, or the `rawPassword` option is not a `Uint8Array`)
|
|
3494
|
+
*
|
|
3495
|
+
* @remarks A value of another type would silently produce an unencrypted archive, and a `rawPassword` passed as a string
|
|
3496
|
+
* would produce an archive that cannot be opened with the equivalent {@link ZipWriterConstructorOptions#password}.
|
|
3497
|
+
*/
|
|
3498
|
+
export const ERR_INVALID_PASSWORD_TYPE: string;
|
|
3377
3499
|
/**
|
|
3378
3500
|
* Entry already exists error (thrown by the filesystem API when adding an entry whose filename already exists)
|
|
3379
3501
|
*/
|
package/index.d.ts
CHANGED
|
@@ -1201,9 +1201,10 @@ export interface GetEntriesOptions {
|
|
|
1201
1201
|
*
|
|
1202
1202
|
* @param value The raw text value.
|
|
1203
1203
|
* @param encoding The encoding of the text.
|
|
1204
|
+
* @param type The type of the decoded text, `"filename"` or `"comment"`.
|
|
1204
1205
|
* @returns The decoded text value or `undefined` if the raw text value should be decoded by zip.js.
|
|
1205
1206
|
*/
|
|
1206
|
-
decodeText?(value: Uint8Array, encoding: string): string | undefined;
|
|
1207
|
+
decodeText?(value: Uint8Array, encoding: string, type: "filename" | "comment"): string | undefined;
|
|
1207
1208
|
/**
|
|
1208
1209
|
* `true` to throw an {@link ERR_AMBIGUOUS_ARCHIVE} error when the archive could be parsed differently by other
|
|
1209
1210
|
* tools. This detects data before or after the zip structure (e.g. a self-extracting archive stub or a
|
|
@@ -1237,6 +1238,42 @@ export interface GetEntriesOptions {
|
|
|
1237
1238
|
* @defaultValue "balanced"
|
|
1238
1239
|
*/
|
|
1239
1240
|
strictness?: "strict" | "balanced" | "tolerant";
|
|
1241
|
+
/**
|
|
1242
|
+
* How strictly the filename of each entry should be validated. A rejected name throws an
|
|
1243
|
+
* {@link ERR_UNSAFE_FILENAME} error carrying the offending name in its `filename` property.
|
|
1244
|
+
*
|
|
1245
|
+
* - `"strict"`: reject the names rejected by `"balanced"`, plus the names that do not map cleanly to a file
|
|
1246
|
+
* path, i.e. empty names and names containing a `"."` path component or an empty one (e.g. `"a//b.txt"`).
|
|
1247
|
+
* - `"balanced"`: reject names that would escape the directory they are extracted into, i.e. names containing
|
|
1248
|
+
* a `".."` path component, and absolute names, i.e. names starting with `"/"`, with a drive letter (e.g.
|
|
1249
|
+
* `"C:/file.txt"`) or with two backslashes (UNC paths).
|
|
1250
|
+
* - `"tolerant"`: never reject a name.
|
|
1251
|
+
*
|
|
1252
|
+
* A backslash is never interpreted as a path separator: it is a valid filename character on UNIX systems, and
|
|
1253
|
+
* it also occurs as the trail byte of legitimate double-byte filenames (e.g. CP932) decoded with another
|
|
1254
|
+
* charset.
|
|
1255
|
+
*
|
|
1256
|
+
* Names are validated, never rewritten, so the filename reported for an entry always matches its central
|
|
1257
|
+
* directory record.
|
|
1258
|
+
*
|
|
1259
|
+
* @defaultValue The value of {@link GetEntriesOptions#strictness}.
|
|
1260
|
+
*/
|
|
1261
|
+
filenameValidation?: "strict" | "balanced" | "tolerant";
|
|
1262
|
+
/**
|
|
1263
|
+
* The function called for normalizing the filename of each entry, e.g. to repair the names rejected by
|
|
1264
|
+
* {@link GetEntriesOptions#filenameValidation}.
|
|
1265
|
+
*
|
|
1266
|
+
* It is called with the decoded filename, after {@link GetEntriesOptions#decodeText} and before the name is
|
|
1267
|
+
* validated, so a name it fails to repair is still rejected. The returned name becomes the name of the entry:
|
|
1268
|
+
* it is used to detect directory entries by their trailing `"/"`, and to detect duplicate filenames when
|
|
1269
|
+
* {@link GetEntriesOptions#checkAmbiguity} is set, so two names normalized into the same name are reported as
|
|
1270
|
+
* an {@link ERR_AMBIGUOUS_ARCHIVE} error instead of silently shadowing each other. The raw filename remains
|
|
1271
|
+
* available in {@link EntryMetaData#rawFilename}.
|
|
1272
|
+
*
|
|
1273
|
+
* @param filename The decoded filename.
|
|
1274
|
+
* @returns The normalized filename or `undefined` to keep the decoded filename.
|
|
1275
|
+
*/
|
|
1276
|
+
normalizeFilename?(filename: string): string | undefined;
|
|
1240
1277
|
/**
|
|
1241
1278
|
* The maximum number of bytes tolerated after the zip structure before the archive is rejected. Defaults to
|
|
1242
1279
|
* `0` when {@link GetEntriesOptions#strictness} is `"strict"`, `65535` when it is `"balanced"`, and `Infinity`
|
|
@@ -1613,6 +1650,27 @@ export interface EntryError extends Error {
|
|
|
1613
1650
|
* The id of the related {@link ZipEntry} (filesystem API).
|
|
1614
1651
|
*/
|
|
1615
1652
|
entryId?: number;
|
|
1653
|
+
/**
|
|
1654
|
+
* The name of the related {@link ZipEntry}, or of the related `FileSystemHandle` when importing
|
|
1655
|
+
* one (filesystem API). Set by {@link ZipDirectoryEntry#addFileSystemHandle} and
|
|
1656
|
+
* {@link ZipDirectoryEntry#exportFileSystemHandle}, which rethrow the original error rather than
|
|
1657
|
+
* wrapping it, so its `message` stays comparable to the exported `ERR_*` constants.
|
|
1658
|
+
*/
|
|
1659
|
+
entryName?: string;
|
|
1660
|
+
/**
|
|
1661
|
+
* The other entries that also failed, when {@link ZipDirectoryEntry#exportFileSystemHandle} runs
|
|
1662
|
+
* with `concurrent` set to `true` and more than one entry fails (filesystem API). The error it is
|
|
1663
|
+
* set on is not repeated in the list, and failures raised deeper in the tree are flattened into
|
|
1664
|
+
* it, so the list holds every failure of the export except this one.
|
|
1665
|
+
*/
|
|
1666
|
+
entryErrors?: EntryError[];
|
|
1667
|
+
/**
|
|
1668
|
+
* The names of the files {@link ZipDirectoryEntry#exportFileSystemHandle} finished writing before
|
|
1669
|
+
* it failed, relative to the exported entry (filesystem API). Directories are not listed. Every
|
|
1670
|
+
* other file of the export is either missing or empty, so this is the only way to tell a file the
|
|
1671
|
+
* export completed from one it created but never filled.
|
|
1672
|
+
*/
|
|
1673
|
+
exportedEntryNames?: string[];
|
|
1616
1674
|
}
|
|
1617
1675
|
/**
|
|
1618
1676
|
* Represents the metadata of an entry in a zip file (Core API).
|
|
@@ -2497,9 +2555,10 @@ export interface ZipWriterConstructorOptions extends WorkerConfiguration {
|
|
|
2497
2555
|
* The function called for encoding the filename and the comment of the entry.
|
|
2498
2556
|
*
|
|
2499
2557
|
* @param text The text to encode.
|
|
2558
|
+
* @param type The type of the encoded text, `"filename"` or `"comment"`.
|
|
2500
2559
|
* @returns The encoded text or `undefined` if the text should be encoded by zip.js.
|
|
2501
2560
|
*/
|
|
2502
|
-
encodeText?(text: string): Uint8Array | undefined;
|
|
2561
|
+
encodeText?(text: string, type: "filename" | "comment"): Uint8Array | undefined;
|
|
2503
2562
|
}
|
|
2504
2563
|
|
|
2505
2564
|
/**
|
|
@@ -2867,6 +2926,10 @@ export class ZipDirectoryEntry extends ZipEntry {
|
|
|
2867
2926
|
/**
|
|
2868
2927
|
* Adds an entry with content provided via a `FileSystemHandle` instance
|
|
2869
2928
|
*
|
|
2929
|
+
* If a handle cannot be read, the original error is rethrown unmodified as an {@link EntryError},
|
|
2930
|
+
* whose {@link EntryError#entryName} is the path of the handle that failed, relative to the parent
|
|
2931
|
+
* of `fileSystemHandle`.
|
|
2932
|
+
*
|
|
2870
2933
|
* @param fileSystemHandle The `fileSystemHandle` instance.
|
|
2871
2934
|
* @param options The options.
|
|
2872
2935
|
* @returns A promise resolving to an array of {@link ZipFileEntry} or a {@link ZipDirectoryEntry} instances.
|
|
@@ -2930,6 +2993,11 @@ export class ZipDirectoryEntry extends ZipEntry {
|
|
|
2930
2993
|
*
|
|
2931
2994
|
* @param reader The {@link Reader} instance.
|
|
2932
2995
|
* @param options The options.
|
|
2996
|
+
*
|
|
2997
|
+
* @remarks The filename of each entry is split into path components to build the tree of entries. Empty
|
|
2998
|
+
* components and `"."` components are ignored, so `"a//b.txt"`, `"./a/b.txt"` and `"a/./b.txt"` all produce
|
|
2999
|
+
* the same `"a/b.txt"` entry. Filenames are normalized and validated beforehand, see
|
|
3000
|
+
* {@link GetEntriesOptions#normalizeFilename} and {@link GetEntriesOptions#filenameValidation}.
|
|
2933
3001
|
*/
|
|
2934
3002
|
importZip(
|
|
2935
3003
|
reader:
|
|
@@ -2978,6 +3046,24 @@ export class ZipDirectoryEntry extends ZipEntry {
|
|
|
2978
3046
|
/**
|
|
2979
3047
|
* 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}.
|
|
2980
3048
|
*
|
|
3049
|
+
* If an entry cannot be written, the original error is rethrown unmodified as an {@link EntryError},
|
|
3050
|
+
* whose {@link EntryError#entryName} is the name of the entry that failed, relative to this entry.
|
|
3051
|
+
*
|
|
3052
|
+
* The export is not atomic and nothing is rolled back, because the target is merged into rather
|
|
3053
|
+
* than replaced: a file that already existed cannot be restored once overwritten. On failure the
|
|
3054
|
+
* target is left as follows, and {@link EntryError#exportedEntryNames} lists the files that
|
|
3055
|
+
* completed:
|
|
3056
|
+
* - files written before the failure are left in place, complete and valid;
|
|
3057
|
+
* - a file whose write started but did not finish is left empty, because it is created before its
|
|
3058
|
+
* content is streamed; this includes the entry that failed and, with `concurrent`, every entry
|
|
3059
|
+
* cancelled alongside it;
|
|
3060
|
+
* - files that already existed in the target keep their previous content unless they were
|
|
3061
|
+
* overwritten in full;
|
|
3062
|
+
* - entries not started yet are missing, as are the directories that would have held them.
|
|
3063
|
+
*
|
|
3064
|
+
* Running the same export again is the supported way to recover, since directories are merged and
|
|
3065
|
+
* files are overwritten.
|
|
3066
|
+
*
|
|
2981
3067
|
* @param directoryHandle The target `FileSystemDirectoryHandle` instance.
|
|
2982
3068
|
* @param options The options.
|
|
2983
3069
|
* @returns A promise resolving to the target `FileSystemDirectoryHandle` instance.
|
|
@@ -3038,6 +3124,11 @@ export interface ZipDirectoryEntryExportFileSystemHandleOptions
|
|
|
3038
3124
|
/**
|
|
3039
3125
|
* `true` to write independent files concurrently instead of one after another.
|
|
3040
3126
|
*
|
|
3127
|
+
* When an entry fails, the entries still in flight are cancelled and the ones not started yet are
|
|
3128
|
+
* skipped, so a failed export stops as early as it does when writing one file after another. An
|
|
3129
|
+
* entry whose write has already been requested may still be created, because the File System
|
|
3130
|
+
* Access API cannot cancel a pending `getFileHandle` or `getDirectoryHandle` call.
|
|
3131
|
+
*
|
|
3041
3132
|
* @defaultValue false
|
|
3042
3133
|
*/
|
|
3043
3134
|
concurrent?: boolean;
|
|
@@ -3322,6 +3413,26 @@ export const ERR_AMBIGUOUS_ARCHIVE: string;
|
|
|
3322
3413
|
* Encryption Specification, which is not supported.
|
|
3323
3414
|
*/
|
|
3324
3415
|
export const ERR_ENCRYPTED_CENTRAL_DIRECTORY: string;
|
|
3416
|
+
/**
|
|
3417
|
+
* Unsafe filename error
|
|
3418
|
+
*
|
|
3419
|
+
* @remarks Thrown when reading an archive containing an entry whose filename is rejected by
|
|
3420
|
+
* {@link GetEntriesOptions#filenameValidation}. The thrown error carries the offending name in its `filename`
|
|
3421
|
+
* property.
|
|
3422
|
+
*/
|
|
3423
|
+
export const ERR_UNSAFE_FILENAME: string;
|
|
3424
|
+
/**
|
|
3425
|
+
* Invalid strictness error (thrown when the `strictness` option is not `"strict"`, `"balanced"` or `"tolerant"`)
|
|
3426
|
+
*/
|
|
3427
|
+
export const ERR_INVALID_STRICTNESS: string;
|
|
3428
|
+
/**
|
|
3429
|
+
* Invalid filenameValidation error (thrown when the `filenameValidation` option is not `"strict"`, `"balanced"` or `"tolerant"`)
|
|
3430
|
+
*/
|
|
3431
|
+
export const ERR_INVALID_FILENAME_VALIDATION: string;
|
|
3432
|
+
/**
|
|
3433
|
+
* Invalid maxAppendedDataSize error (thrown when the `maxAppendedDataSize` option is not a number greater than or equal to 0)
|
|
3434
|
+
*/
|
|
3435
|
+
export const ERR_INVALID_MAX_APPENDED_DATA_SIZE: string;
|
|
3325
3436
|
/**
|
|
3326
3437
|
* Iteration completed too soon error
|
|
3327
3438
|
*/
|
|
@@ -3374,6 +3485,17 @@ export const ERR_INVALID_MSDOS_ATTRIBUTES: string;
|
|
|
3374
3485
|
* Invalid msdosAttributes error (thrown when the `msdosAttributes` option is not an object with boolean flags)
|
|
3375
3486
|
*/
|
|
3376
3487
|
export const ERR_INVALID_MSDOS_DATA: string;
|
|
3488
|
+
/**
|
|
3489
|
+
* Invalid level error (thrown when the `level` option is not an integer in the range 0..9)
|
|
3490
|
+
*/
|
|
3491
|
+
export const ERR_INVALID_LEVEL: string;
|
|
3492
|
+
/**
|
|
3493
|
+
* Invalid password error (thrown when the `password` option is not a string, or the `rawPassword` option is not a `Uint8Array`)
|
|
3494
|
+
*
|
|
3495
|
+
* @remarks A value of another type would silently produce an unencrypted archive, and a `rawPassword` passed as a string
|
|
3496
|
+
* would produce an archive that cannot be opened with the equivalent {@link ZipWriterConstructorOptions#password}.
|
|
3497
|
+
*/
|
|
3498
|
+
export const ERR_INVALID_PASSWORD_TYPE: string;
|
|
3377
3499
|
/**
|
|
3378
3500
|
* Entry already exists error (thrown by the filesystem API when adding an entry whose filename already exists)
|
|
3379
3501
|
*/
|