@procedures/archive 0.0.0-stage → 0.2.3

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 (74) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +95 -2
  3. package/dist/.tsbuildinfo +1 -0
  4. package/dist/errors.d.ts +27 -0
  5. package/dist/errors.d.ts.map +1 -0
  6. package/dist/errors.js +15 -0
  7. package/dist/errors.js.map +1 -0
  8. package/dist/format.d.ts +25 -0
  9. package/dist/format.d.ts.map +1 -0
  10. package/dist/format.js +60 -0
  11. package/dist/format.js.map +1 -0
  12. package/dist/index.d.ts +8 -0
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +10 -0
  15. package/dist/index.js.map +1 -0
  16. package/dist/module.d.ts +34 -0
  17. package/dist/module.d.ts.map +1 -0
  18. package/dist/module.js +148 -0
  19. package/dist/module.js.map +1 -0
  20. package/dist/paths.d.ts +58 -0
  21. package/dist/paths.d.ts.map +1 -0
  22. package/dist/paths.js +205 -0
  23. package/dist/paths.js.map +1 -0
  24. package/dist/procedures/archive/create.d.ts +14 -0
  25. package/dist/procedures/archive/create.d.ts.map +1 -0
  26. package/dist/procedures/archive/create.js +81 -0
  27. package/dist/procedures/archive/create.js.map +1 -0
  28. package/dist/procedures/archive/extract.d.ts +17 -0
  29. package/dist/procedures/archive/extract.d.ts.map +1 -0
  30. package/dist/procedures/archive/extract.js +101 -0
  31. package/dist/procedures/archive/extract.js.map +1 -0
  32. package/dist/procedures/archive/index.d.ts +4 -0
  33. package/dist/procedures/archive/index.d.ts.map +1 -0
  34. package/dist/procedures/archive/index.js +4 -0
  35. package/dist/procedures/archive/index.js.map +1 -0
  36. package/dist/procedures/archive/list.d.ts +15 -0
  37. package/dist/procedures/archive/list.d.ts.map +1 -0
  38. package/dist/procedures/archive/list.js +47 -0
  39. package/dist/procedures/archive/list.js.map +1 -0
  40. package/dist/register.d.ts +6 -0
  41. package/dist/register.d.ts.map +1 -0
  42. package/dist/register.js +8 -0
  43. package/dist/register.js.map +1 -0
  44. package/dist/tar.d.ts +38 -0
  45. package/dist/tar.d.ts.map +1 -0
  46. package/dist/tar.js +193 -0
  47. package/dist/tar.js.map +1 -0
  48. package/dist/types.d.ts +81 -0
  49. package/dist/types.d.ts.map +1 -0
  50. package/dist/types.js +8 -0
  51. package/dist/types.js.map +1 -0
  52. package/dist/walk.d.ts +34 -0
  53. package/dist/walk.d.ts.map +1 -0
  54. package/dist/walk.js +67 -0
  55. package/dist/walk.js.map +1 -0
  56. package/dist/zip.d.ts +57 -0
  57. package/dist/zip.d.ts.map +1 -0
  58. package/dist/zip.js +397 -0
  59. package/dist/zip.js.map +1 -0
  60. package/package.json +77 -3
  61. package/src/errors.ts +33 -0
  62. package/src/format.ts +64 -0
  63. package/src/index.ts +9 -0
  64. package/src/module.ts +192 -0
  65. package/src/paths.ts +230 -0
  66. package/src/procedures/archive/create.ts +84 -0
  67. package/src/procedures/archive/extract.ts +103 -0
  68. package/src/procedures/archive/index.ts +3 -0
  69. package/src/procedures/archive/list.ts +50 -0
  70. package/src/register.ts +10 -0
  71. package/src/tar.ts +198 -0
  72. package/src/types.ts +101 -0
  73. package/src/walk.ts +85 -0
  74. package/src/zip.ts +419 -0
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Type definitions of the procedures of this package
3
+ *
4
+ * mark procedure new adds the types of each new procedure here. The zod schemas are in
5
+ * `module.ts`: an exported schema needs a written type (isolatedDeclarations).
6
+ */
7
+ /** The formats of an archive. `tar` is a tar file without compression. */
8
+ export type ArchiveFormat = "tar.gz" | "tar" | "zip";
9
+ /** The kind of an entry of an archive. `other` is a device, a FIFO or another special file. */
10
+ export type ArchiveEntryKind = "file" | "directory" | "symlink" | "hardlink" | "other";
11
+ export interface ArchiveCreateInput {
12
+ /** The archive to make. */
13
+ output: string;
14
+ /** A folder: the archive gets its content, with paths relative to the folder. */
15
+ source?: string | undefined;
16
+ /** Files and folders, relative to `cwd`. A folder goes in with its content. */
17
+ files?: string[] | undefined;
18
+ /** The base folder of `files`. The default is the working folder of the process. */
19
+ cwd?: string | undefined;
20
+ /** The format. The default comes from the name of `output`: `.tar.gz`, `.tgz`, `.tar` or `.zip`. */
21
+ format?: ArchiveFormat | undefined;
22
+ /** True: replace an existing archive. The default is false: an existing archive is an error. */
23
+ overwrite?: boolean | undefined;
24
+ }
25
+ export interface ArchiveCreateOutput {
26
+ /** The absolute path of the archive. */
27
+ path: string;
28
+ format: ArchiveFormat;
29
+ /** The number of entries: files, folders and links. */
30
+ entries: number;
31
+ /** The size of the archive, in bytes. */
32
+ bytes: number;
33
+ }
34
+ export interface ArchiveExtractInput {
35
+ /** The archive. */
36
+ archive: string;
37
+ /** The folder that gets the content. The procedure makes it when it does not exist. */
38
+ target: string;
39
+ /** The format. The default comes from the first bytes of the archive. */
40
+ format?: ArchiveFormat | undefined;
41
+ /** True: replace an existing file. The default is false: an existing file is an error, and nothing changes. */
42
+ overwrite?: boolean | undefined;
43
+ }
44
+ export interface ArchiveExtractOutput {
45
+ /** The absolute path of the target folder. */
46
+ target: string;
47
+ format: ArchiveFormat;
48
+ files: number;
49
+ directories: number;
50
+ /** The symbolic links and the hard links. */
51
+ links: number;
52
+ /** The bytes of the files. */
53
+ bytes: number;
54
+ }
55
+ export interface ArchiveListInput {
56
+ /** The archive. */
57
+ archive: string;
58
+ /** The format. The default comes from the first bytes of the archive. */
59
+ format?: ArchiveFormat | undefined;
60
+ }
61
+ /** One entry of an archive. */
62
+ export interface ArchiveEntry {
63
+ /** The path in the archive, as the archive has it. */
64
+ path: string;
65
+ kind: ArchiveEntryKind;
66
+ /** The size of the content, in bytes. */
67
+ size: number;
68
+ /** The mode bits (`0o644`), when the archive has them. */
69
+ mode?: number | undefined;
70
+ /** The time of the last change, as an ISO text, when the archive has it. */
71
+ mtime?: string | undefined;
72
+ /** The target of a link. */
73
+ linkTarget?: string | undefined;
74
+ }
75
+ export interface ArchiveListOutput {
76
+ format: ArchiveFormat;
77
+ entries: ArchiveEntry[];
78
+ /** The sum of the sizes of the entries, in bytes. */
79
+ bytes: number;
80
+ }
81
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,0EAA0E;AAC1E,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,KAAK,GAAG,KAAK,CAAC;AAErD,+FAA+F;AAC/F,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,WAAW,GAAG,SAAS,GAAG,UAAU,GAAG,OAAO,CAAC;AAMvF,MAAM,WAAW,kBAAkB;IACjC,2BAA2B;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,iFAAiF;IACjF,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,+EAA+E;IAC/E,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAC7B,oFAAoF;IACpF,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,oGAAoG;IACpG,MAAM,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;IACnC,gGAAgG;IAChG,SAAS,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACjC;AAED,MAAM,WAAW,mBAAmB;IAClC,wCAAwC;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,aAAa,CAAC;IACtB,uDAAuD;IACvD,OAAO,EAAE,MAAM,CAAC;IAChB,yCAAyC;IACzC,KAAK,EAAE,MAAM,CAAC;CACf;AAMD,MAAM,WAAW,mBAAmB;IAClC,mBAAmB;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,uFAAuF;IACvF,MAAM,EAAE,MAAM,CAAC;IACf,yEAAyE;IACzE,MAAM,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;IACnC,+GAA+G;IAC/G,SAAS,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACjC;AAED,MAAM,WAAW,oBAAoB;IACnC,8CAA8C;IAC9C,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,aAAa,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,6CAA6C;IAC7C,KAAK,EAAE,MAAM,CAAC;IACd,8BAA8B;IAC9B,KAAK,EAAE,MAAM,CAAC;CACf;AAMD,MAAM,WAAW,gBAAgB;IAC/B,mBAAmB;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,yEAAyE;IACzE,MAAM,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;CACpC;AAED,+BAA+B;AAC/B,MAAM,WAAW,YAAY;IAC3B,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,gBAAgB,CAAC;IACvB,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,0DAA0D;IAC1D,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,4EAA4E;IAC5E,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,4BAA4B;IAC5B,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACjC;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,qDAAqD;IACrD,KAAK,EAAE,MAAM,CAAC;CACf"}
package/dist/types.js ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Type definitions of the procedures of this package
3
+ *
4
+ * mark procedure new adds the types of each new procedure here. The zod schemas are in
5
+ * `module.ts`: an exported schema needs a written type (isolatedDeclarations).
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
package/dist/walk.d.ts ADDED
@@ -0,0 +1,34 @@
1
+ /**
2
+ * The walk of `archive.create`: each file, folder and symbolic link under the inputs, in a fixed
3
+ * order. The walk does not follow a link: the archive gets the link itself.
4
+ */
5
+ /** One path for the archive. */
6
+ export interface WalkEntry {
7
+ /** The name in the archive: relative, with `/`. */
8
+ readonly name: string;
9
+ /** The absolute path on the disk. */
10
+ readonly path: string;
11
+ readonly kind: "file" | "directory" | "symlink";
12
+ readonly size: number;
13
+ readonly mode: number;
14
+ readonly mtime: Date;
15
+ readonly linkTarget?: string | undefined;
16
+ }
17
+ /** The limits and the paths to leave out (the new archive and its temporary file). */
18
+ export interface WalkOptions {
19
+ readonly maxEntries: number;
20
+ readonly maxBytes: number;
21
+ readonly exclude: ReadonlySet<string>;
22
+ }
23
+ /**
24
+ * This function gives the target of a link with `/`, as an archive keeps it. Windows gives `..\a.txt`
25
+ * for a link that Node made from `../a.txt`. On the other systems, a `\` is a part of a name.
26
+ */
27
+ export declare function portableLinkTarget(target: string, separator?: string): string;
28
+ /** This function walks the names (relative to `base`) and gives each entry for the archive. */
29
+ export declare function walk(base: string, names: readonly string[], options: WalkOptions): Promise<WalkEntry[]>;
30
+ /** The names of the content of a folder, sorted. */
31
+ export declare function folderNames(folder: string): Promise<string[]>;
32
+ /** The absolute path of a name under a base. */
33
+ export declare function under(base: string, name: string): string;
34
+ //# sourceMappingURL=walk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"walk.d.ts","sourceRoot":"","sources":["../src/walk.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,gCAAgC;AAChC,MAAM,WAAW,SAAS;IACxB,mDAAmD;IACnD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,qCAAqC;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAAC;IAChD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC;IACrB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1C;AAED,sFAAsF;AACtF,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CACvC;AAID;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,GAAE,MAAY,GAAG,MAAM,CAElF;AAED,+FAA+F;AAC/F,wBAAsB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAkC7G;AAED,oDAAoD;AACpD,wBAAsB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAEnE;AAED,gDAAgD;AAChD,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAExD"}
package/dist/walk.js ADDED
@@ -0,0 +1,67 @@
1
+ /**
2
+ * The walk of `archive.create`: each file, folder and symbolic link under the inputs, in a fixed
3
+ * order. The walk does not follow a link: the archive gets the link itself.
4
+ */
5
+ import { lstat, readdir, readlink } from "node:fs/promises";
6
+ import { join, resolve, sep } from "node:path";
7
+ import { ArchiveError } from "./errors.js";
8
+ const byName = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
9
+ /**
10
+ * This function gives the target of a link with `/`, as an archive keeps it. Windows gives `..\a.txt`
11
+ * for a link that Node made from `../a.txt`. On the other systems, a `\` is a part of a name.
12
+ */
13
+ export function portableLinkTarget(target, separator = sep) {
14
+ return separator === "\\" ? target.replaceAll("\\", "/") : target;
15
+ }
16
+ /** This function walks the names (relative to `base`) and gives each entry for the archive. */
17
+ export async function walk(base, names, options) {
18
+ const entries = [];
19
+ const seen = new Set();
20
+ let bytes = 0;
21
+ const visit = async (name) => {
22
+ const path = resolve(base, ...name.split("/"));
23
+ if (options.exclude.has(path) || seen.has(name))
24
+ return;
25
+ seen.add(name);
26
+ let stats;
27
+ try {
28
+ stats = await lstat(path);
29
+ }
30
+ catch {
31
+ throw new ArchiveError("UNSAFE_PATH", `${path} does not exist`, name);
32
+ }
33
+ if (entries.length >= options.maxEntries)
34
+ throw new ArchiveError("TOO_LARGE", `The archive gets more entries than the limit of ${options.maxEntries}`, name);
35
+ const common = { name, path, size: 0, mode: stats.mode & 0o7777, mtime: stats.mtime };
36
+ if (stats.isSymbolicLink()) {
37
+ entries.push({ ...common, kind: "symlink", linkTarget: portableLinkTarget(await readlink(path)) });
38
+ }
39
+ else if (stats.isDirectory()) {
40
+ entries.push({ ...common, kind: "directory" });
41
+ const children = (await readdir(path)).sort(byName);
42
+ for (const child of children)
43
+ await visit(`${name}/${child}`);
44
+ }
45
+ else if (stats.isFile()) {
46
+ bytes += stats.size;
47
+ if (bytes > options.maxBytes)
48
+ throw new ArchiveError("TOO_LARGE", `The files have more than ${options.maxBytes} bytes`, name);
49
+ entries.push({ ...common, kind: "file", size: stats.size });
50
+ }
51
+ else {
52
+ throw new ArchiveError("UNSUPPORTED_ENTRY", `${path} is a special file (a socket, a device or a FIFO)`, name);
53
+ }
54
+ };
55
+ for (const name of names)
56
+ await visit(name);
57
+ return entries;
58
+ }
59
+ /** The names of the content of a folder, sorted. */
60
+ export async function folderNames(folder) {
61
+ return (await readdir(folder)).sort(byName);
62
+ }
63
+ /** The absolute path of a name under a base. */
64
+ export function under(base, name) {
65
+ return join(base, ...name.split("/"));
66
+ }
67
+ //# sourceMappingURL=walk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"walk.js","sourceRoot":"","sources":["../src/walk.ts"],"names":[],"mappings":"AAAA;;;GAGG;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AAE,4BAA4B,OAAO,CAAC,QAAQ,QAAQ,EAAE,IAAI,CAAC,CAAC;YAC9H,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;QAC9D,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,YAAY,CAAC,mBAAmB,EAAE,GAAG,IAAI,mDAAmD,EAAE,IAAI,CAAC,CAAC;QAChH,CAAC;IACH,CAAC,CAAC;IAEF,KAAK,MAAM,IAAI,IAAI,KAAK;QAAE,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC;IAC5C,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,oDAAoD;AACpD,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,MAAc;IAC9C,OAAO,CAAC,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC9C,CAAC;AAED,gDAAgD;AAChD,MAAM,UAAU,KAAK,CAAC,IAAY,EAAE,IAAY;IAC9C,OAAO,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;AACxC,CAAC"}
package/dist/zip.d.ts ADDED
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Zip archives on `node:zlib` (roadmap R46).
3
+ *
4
+ * The package reads and writes zip itself, for two reasons. The reader needs the external
5
+ * attributes of each entry, to see a symbolic link, and a limit on the bytes of each entry
6
+ * against a zip bomb. A zip library that decodes in memory gives neither.
7
+ *
8
+ * - The reader takes the central directory: stored and deflated entries, UTF-8 names, and the
9
+ * zip64 fields. It refuses an encrypted entry, another method and an archive on more disks.
10
+ * - The extract streams each entry and stops when it gets more bytes than the entry declares.
11
+ * It examines the size and the CRC-32 of each entry.
12
+ * - The writer stores each file, or deflates it when that is smaller. It writes no zip64 fields:
13
+ * it refuses more than 65535 entries and an archive of 4 GiB or more.
14
+ */
15
+ import { type FileHandle } from "node:fs/promises";
16
+ /** The CRC-32 of bytes, continued from `crc` (0 for new bytes). */
17
+ export declare function crc32(bytes: Uint8Array, crc?: number): number;
18
+ /** One entry of the central directory. */
19
+ export interface ZipEntry {
20
+ readonly name: string;
21
+ readonly kind: "file" | "directory" | "symlink";
22
+ readonly method: number;
23
+ readonly flags: number;
24
+ readonly crc: number;
25
+ readonly compressedSize: number;
26
+ readonly size: number;
27
+ readonly localOffset: number;
28
+ /** The mode bits of a Unix entry, without the type. */
29
+ readonly mode: number | undefined;
30
+ readonly mtime: Date;
31
+ }
32
+ /** This function reads the central directory of a zip. It throws `TOO_LARGE` for more than `maxEntries` entries. */
33
+ export declare function readZipDirectory(path: string, maxEntries: number): Promise<ZipEntry[]>;
34
+ /**
35
+ * This function writes the content of a file entry to `destination`, with the checks. The file
36
+ * must not exist: the caller removes an old file first, so the write never follows a link.
37
+ */
38
+ export declare function extractZipFile(archive: string, entry: ZipEntry, destination: string, mode?: number): Promise<void>;
39
+ /** This function gives the target of a symbolic link entry: its content, as text. */
40
+ export declare function readZipLink(archive: string, entry: ZipEntry): Promise<string>;
41
+ /** One entry for the writer. */
42
+ export interface ZipWriteEntry {
43
+ /** The name in the archive. A folder ends with `/`: the writer adds it. */
44
+ readonly name: string;
45
+ readonly kind: "file" | "directory" | "symlink";
46
+ /** The content of a file, or the target of a link as UTF-8. A function loads it when the writer needs it. */
47
+ readonly data?: Uint8Array | (() => Promise<Uint8Array>) | undefined;
48
+ /** The mode bits, without the type. */
49
+ readonly mode?: number | undefined;
50
+ readonly mtime?: Date | undefined;
51
+ }
52
+ /**
53
+ * This function writes a zip to an open file. The names are not examined here: `archive.create`
54
+ * gives only the relative paths of a walk, and a test gives hostile names on purpose.
55
+ */
56
+ export declare function writeZip(handle: FileHandle, entries: readonly ZipWriteEntry[]): Promise<number>;
57
+ //# sourceMappingURL=zip.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zip.d.ts","source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