zip-writer 1.0.0 → 1.0.1

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 (45) hide show
  1. package/dist/constants.d.ts +21 -0
  2. package/dist/constants.d.ts.map +1 -0
  3. package/{src/constants.ts → dist/constants.js} +1 -5
  4. package/dist/constants.js.map +1 -0
  5. package/dist/crc-lookup.d.ts +6 -0
  6. package/dist/crc-lookup.d.ts.map +1 -0
  7. package/dist/crc-lookup.js +22 -0
  8. package/dist/crc-lookup.js.map +1 -0
  9. package/{src/crc.ts → dist/crc.d.ts} +2 -39
  10. package/dist/crc.d.ts.map +1 -0
  11. package/dist/crc.js +62 -0
  12. package/dist/crc.js.map +1 -0
  13. package/dist/index.d.ts +104 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +245 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/utils.d.ts +4 -0
  18. package/dist/utils.d.ts.map +1 -0
  19. package/dist/utils.js +12 -0
  20. package/dist/utils.js.map +1 -0
  21. package/dist/write-central-directory.d.ts +14 -0
  22. package/dist/write-central-directory.d.ts.map +1 -0
  23. package/dist/write-central-directory.js +279 -0
  24. package/dist/write-central-directory.js.map +1 -0
  25. package/dist/write-entry.d.ts +24 -0
  26. package/dist/write-entry.d.ts.map +1 -0
  27. package/dist/write-entry.js +173 -0
  28. package/dist/write-entry.js.map +1 -0
  29. package/package.json +12 -3
  30. package/.claude/settings.local.json +0 -11
  31. package/.github/workflows/test.yml +0 -36
  32. package/.husky/pre-commit +0 -1
  33. package/eslint.config.mjs +0 -9
  34. package/src/crc-lookup.ts +0 -27
  35. package/src/index.ts +0 -342
  36. package/src/utils.ts +0 -17
  37. package/src/write-central-directory.ts +0 -405
  38. package/src/write-entry.ts +0 -246
  39. package/test/commands.ts +0 -47
  40. package/test/crc.test.ts +0 -45
  41. package/test/integration.test.ts +0 -483
  42. package/test/utils.ts +0 -40
  43. package/tsconfig.json +0 -36
  44. package/tsconfig.node.json +0 -10
  45. package/vitest.config.ts +0 -46
@@ -0,0 +1,21 @@
1
+ export declare const LOCAL_FILE_HEADER_SIGNATURE = 1347093252;
2
+ export declare const DATA_DESCRIPTOR_SIGNATURE = 1347094280;
3
+ export declare const CENTRAL_DIRECTORY_SIGNATURE = 1347092738;
4
+ export declare const END_OF_CENTRAL_DIR_SIGNATURE = 1347093766;
5
+ export declare const ZIP64_END_OF_CENTRAL_DIR_SIGNATURE = 1347094022;
6
+ export declare const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE = 1347094023;
7
+ export declare const VERSION_MADE_BY = 45;
8
+ export declare const VERSION_NEEDED_STANDARD = 20;
9
+ export declare const VERSION_NEEDED_ZIP64 = 45;
10
+ export declare const GENERAL_PURPOSE_FLAGS = 2056;
11
+ export declare const COMPRESSION_METHOD_STORE = 0;
12
+ export declare const COMPRESSION_METHOD_DEFLATE = 8;
13
+ export declare const LOCAL_FILE_HEADER_SIZE = 30;
14
+ export declare const CENTRAL_DIRECTORY_HEADER_SIZE = 46;
15
+ export declare const DATA_DESCRIPTOR_SIZE = 16;
16
+ export declare const DATA_DESCRIPTOR_SIZE_ZIP64 = 24;
17
+ export declare const EOCD_SIZE = 22;
18
+ export declare const EOCD64_SIZE = 56;
19
+ export declare const EOCD64_LOCATOR_SIZE = 20;
20
+ export declare const ZIP64_LIMIT: bigint;
21
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,2BAA2B,aAAa,CAAC;AACtD,eAAO,MAAM,yBAAyB,aAAa,CAAC;AACpD,eAAO,MAAM,2BAA2B,aAAa,CAAC;AACtD,eAAO,MAAM,4BAA4B,aAAa,CAAC;AACvD,eAAO,MAAM,kCAAkC,aAAa,CAAC;AAC7D,eAAO,MAAM,0CAA0C,aAAa,CAAC;AAGrE,eAAO,MAAM,eAAe,KAAK,CAAC;AAClC,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAC1C,eAAO,MAAM,oBAAoB,KAAK,CAAC;AAGvC,eAAO,MAAM,qBAAqB,OAAwB,CAAC;AAG3D,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAC1C,eAAO,MAAM,0BAA0B,IAAI,CAAC;AAG5C,eAAO,MAAM,sBAAsB,KAAK,CAAC;AACzC,eAAO,MAAM,6BAA6B,KAAK,CAAC;AAChD,eAAO,MAAM,oBAAoB,KAAK,CAAC;AACvC,eAAO,MAAM,0BAA0B,KAAK,CAAC;AAC7C,eAAO,MAAM,SAAS,KAAK,CAAC;AAC5B,eAAO,MAAM,WAAW,KAAK,CAAC;AAC9B,eAAO,MAAM,mBAAmB,KAAK,CAAC;AAGtC,eAAO,MAAM,WAAW,QAAqB,CAAC"}
@@ -5,19 +5,15 @@ export const CENTRAL_DIRECTORY_SIGNATURE = 0x504b0102; // "PK\x01\x02"
5
5
  export const END_OF_CENTRAL_DIR_SIGNATURE = 0x504b0506; // "PK\x05\x06"
6
6
  export const ZIP64_END_OF_CENTRAL_DIR_SIGNATURE = 0x504b0606; // "PK\x06\x06"
7
7
  export const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE = 0x504b0607; // "PK\x06\x07"
8
-
9
8
  // Version constants
10
9
  export const VERSION_MADE_BY = 45; // Version 4.5 (ZIP64 support)
11
10
  export const VERSION_NEEDED_STANDARD = 20; // Version 2.0
12
11
  export const VERSION_NEEDED_ZIP64 = 45; // Version 4.5 for ZIP64
13
-
14
12
  // Flags
15
13
  export const GENERAL_PURPOSE_FLAGS = 0b0000_1000_0000_1000; // Bit 3: data descriptor, Bit 11: UTF-8
16
-
17
14
  // Compression methods
18
15
  export const COMPRESSION_METHOD_STORE = 0;
19
16
  export const COMPRESSION_METHOD_DEFLATE = 8;
20
-
21
17
  // Size constants
22
18
  export const LOCAL_FILE_HEADER_SIZE = 30;
23
19
  export const CENTRAL_DIRECTORY_HEADER_SIZE = 46;
@@ -26,6 +22,6 @@ export const DATA_DESCRIPTOR_SIZE_ZIP64 = 24;
26
22
  export const EOCD_SIZE = 22;
27
23
  export const EOCD64_SIZE = 56;
28
24
  export const EOCD64_LOCATOR_SIZE = 20;
29
-
30
25
  // Limits
31
26
  export const ZIP64_LIMIT = BigInt(0xffffffff);
27
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,MAAM,CAAC,MAAM,2BAA2B,GAAG,UAAU,CAAC,CAAC,eAAe;AACtE,MAAM,CAAC,MAAM,yBAAyB,GAAG,UAAU,CAAC,CAAC,eAAe;AACpE,MAAM,CAAC,MAAM,2BAA2B,GAAG,UAAU,CAAC,CAAC,eAAe;AACtE,MAAM,CAAC,MAAM,4BAA4B,GAAG,UAAU,CAAC,CAAC,eAAe;AACvE,MAAM,CAAC,MAAM,kCAAkC,GAAG,UAAU,CAAC,CAAC,eAAe;AAC7E,MAAM,CAAC,MAAM,0CAA0C,GAAG,UAAU,CAAC,CAAC,eAAe;AAErF,oBAAoB;AACpB,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAC,CAAC,8BAA8B;AACjE,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,CAAC,CAAC,cAAc;AACzD,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,CAAC,CAAC,wBAAwB;AAEhE,QAAQ;AACR,MAAM,CAAC,MAAM,qBAAqB,GAAG,qBAAqB,CAAC,CAAC,wCAAwC;AAEpG,sBAAsB;AACtB,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC;AAC1C,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC;AAE5C,iBAAiB;AACjB,MAAM,CAAC,MAAM,sBAAsB,GAAG,EAAE,CAAC;AACzC,MAAM,CAAC,MAAM,6BAA6B,GAAG,EAAE,CAAC;AAChD,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AACvC,MAAM,CAAC,MAAM,0BAA0B,GAAG,EAAE,CAAC;AAC7C,MAAM,CAAC,MAAM,SAAS,GAAG,EAAE,CAAC;AAC5B,MAAM,CAAC,MAAM,WAAW,GAAG,EAAE,CAAC;AAC9B,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAEtC,SAAS;AACT,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * From https://github.com/holepunchto/crc-universal/blob/main/lookup.js
3
+ * Licensed under Apache-2.0
4
+ */
5
+ export declare const lookup: Uint32Array<ArrayBuffer>[];
6
+ //# sourceMappingURL=crc-lookup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crc-lookup.d.ts","sourceRoot":"","sources":["../src/crc-lookup.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,eAAO,MAAM,MAAM,EAAoB,WAAW,CAAC,WAAW,CAAC,EAAE,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * From https://github.com/holepunchto/crc-universal/blob/main/lookup.js
3
+ * Licensed under Apache-2.0
4
+ */
5
+ export const lookup = new Array(16);
6
+ for (let i = 0; i < 16; i++) {
7
+ lookup[i] = new Uint32Array(0x100);
8
+ }
9
+ for (let i = 0; i <= 0xff; i++) {
10
+ let crc = i;
11
+ for (let j = 0; j < 8; j++) {
12
+ crc = (crc >>> 1) ^ ((crc & 1) * 0xedb88320);
13
+ }
14
+ lookup[0][i] = crc;
15
+ }
16
+ for (let i = 0; i <= 0xff; i++) {
17
+ for (let j = 1; j < 16; j++) {
18
+ lookup[j][i] =
19
+ (lookup[j - 1][i] >>> 8) ^ lookup[0][lookup[j - 1][i] & 0xff];
20
+ }
21
+ }
22
+ //# sourceMappingURL=crc-lookup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crc-lookup.js","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* 3. This notice may not be removed or altered from any source distribution.
22
22
  */
23
-
24
- import { lookup } from "./crc-lookup.js";
25
-
26
23
  /**
27
24
  * Computes a 32-bit Cyclic Redundancy Check checksum of data. If value is
28
25
  * specified, it is used as the starting value of the checksum, otherwise, 0 is
@@ -32,39 +29,5 @@ import { lookup } from "./crc-lookup.js";
32
29
  * @param value - An optional starting value. It must be a 32-bit unsigned integer. Default: 0
33
30
  * @returns The computed CRC32 checksum.
34
31
  */
35
- export function crc32(
36
- data: Uint8Array<ArrayBuffer>,
37
- value: number = 0
38
- ): number {
39
- let crc = ~value;
40
- let i = 0;
41
- let length = data.byteLength;
42
-
43
- while (length >= 16) {
44
- crc =
45
- lookup[15][data[i++] ^ (crc & 0xff)] ^
46
- lookup[14][data[i++] ^ ((crc >>> 8) & 0xff)] ^
47
- lookup[13][data[i++] ^ ((crc >>> 16) & 0xff)] ^
48
- lookup[12][data[i++] ^ (crc >>> 24)] ^
49
- lookup[11][data[i++]] ^
50
- lookup[10][data[i++]] ^
51
- lookup[9][data[i++]] ^
52
- lookup[8][data[i++]] ^
53
- lookup[7][data[i++]] ^
54
- lookup[6][data[i++]] ^
55
- lookup[5][data[i++]] ^
56
- lookup[4][data[i++]] ^
57
- lookup[3][data[i++]] ^
58
- lookup[2][data[i++]] ^
59
- lookup[1][data[i++]] ^
60
- lookup[0][data[i++]];
61
-
62
- length -= 16;
63
- }
64
-
65
- while (length-- > 0) {
66
- crc = (crc >>> 8) ^ lookup[0][(crc & 0xff) ^ data[i++]];
67
- }
68
-
69
- return ~crc >>> 0;
70
- }
32
+ export declare function crc32(data: Uint8Array<ArrayBuffer>, value?: number): number;
33
+ //# sourceMappingURL=crc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crc.d.ts","sourceRoot":"","sources":["../src/crc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAIH;;;;;;;;GAQG;AACH,wBAAgB,KAAK,CACnB,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,EAC7B,KAAK,GAAE,MAAU,GAChB,MAAM,CAgCR"}
package/dist/crc.js ADDED
@@ -0,0 +1,62 @@
1
+ /**
2
+ * The JavaScript implementation of CRC32 is a version of the slice-by-16 algorithm
3
+ * as implemented by Stephan Brumme, see https://github.com/stbrumme/crc32.
4
+ *
5
+ * Copyright (c) 2011-2016 Stephan Brumme
6
+ *
7
+ * This software is provided 'as-is', without any express or implied warranty.
8
+ * In no event will the authors be held liable for any damages arising from the
9
+ * use of this software.
10
+ *
11
+ * Permission is granted to anyone to use this software for any purpose,
12
+ * including commercial applications, and to alter it and redistribute it freely,
13
+ * subject to the following restrictions:
14
+ *
15
+ * 1. The origin of this software must not be misrepresented; you must not claim
16
+ * that you wrote the original software.
17
+ * If you use this software in a product, an acknowledgment in the product
18
+ * documentation would be appreciated but is not required.
19
+ * 2. Altered source versions must be plainly marked as such, and must not be
20
+ * misrepresented as being the original software.
21
+ * 3. This notice may not be removed or altered from any source distribution.
22
+ */
23
+ import { lookup } from "./crc-lookup.js";
24
+ /**
25
+ * Computes a 32-bit Cyclic Redundancy Check checksum of data. If value is
26
+ * specified, it is used as the starting value of the checksum, otherwise, 0 is
27
+ * used as the starting value.
28
+ *
29
+ * @param data - The input data to compute the checksum for.
30
+ * @param value - An optional starting value. It must be a 32-bit unsigned integer. Default: 0
31
+ * @returns The computed CRC32 checksum.
32
+ */
33
+ export function crc32(data, value = 0) {
34
+ let crc = ~value;
35
+ let i = 0;
36
+ let length = data.byteLength;
37
+ while (length >= 16) {
38
+ crc =
39
+ lookup[15][data[i++] ^ (crc & 0xff)] ^
40
+ lookup[14][data[i++] ^ ((crc >>> 8) & 0xff)] ^
41
+ lookup[13][data[i++] ^ ((crc >>> 16) & 0xff)] ^
42
+ lookup[12][data[i++] ^ (crc >>> 24)] ^
43
+ lookup[11][data[i++]] ^
44
+ lookup[10][data[i++]] ^
45
+ lookup[9][data[i++]] ^
46
+ lookup[8][data[i++]] ^
47
+ lookup[7][data[i++]] ^
48
+ lookup[6][data[i++]] ^
49
+ lookup[5][data[i++]] ^
50
+ lookup[4][data[i++]] ^
51
+ lookup[3][data[i++]] ^
52
+ lookup[2][data[i++]] ^
53
+ lookup[1][data[i++]] ^
54
+ lookup[0][data[i++]];
55
+ length -= 16;
56
+ }
57
+ while (length-- > 0) {
58
+ crc = (crc >>> 8) ^ lookup[0][(crc & 0xff) ^ data[i++]];
59
+ }
60
+ return ~crc >>> 0;
61
+ }
62
+ //# sourceMappingURL=crc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crc.js","sourceRoot":"","sources":["../src/crc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC;;;;;;;;GAQG;AACH,MAAM,UAAU,KAAK,CACnB,IAA6B,EAC7B,QAAgB,CAAC;IAEjB,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC;IACjB,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,IAAI,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC;IAE7B,OAAO,MAAM,IAAI,EAAE,EAAE,CAAC;QACpB,GAAG;YACD,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC;gBACpC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;gBAC5C,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;gBAC7C,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,KAAK,EAAE,CAAC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
1
+ export interface EntryOptions {
2
+ /** Entry name including internal path */
3
+ name: string;
4
+ /** Entry comment */
5
+ comment?: string;
6
+ /** Entry date */
7
+ date?: Date;
8
+ /** Entry permissions */
9
+ mode?: number;
10
+ /** Compression method to `STORE` (defaults to `DEFLATE`) */
11
+ store?: boolean;
12
+ }
13
+ export interface EntryInfoZip64 extends EntryOptions {
14
+ /** Byte offset of the local file header within the ZIP archive */
15
+ startOffset: bigint;
16
+ /** CRC32 checksum of the uncompressed data */
17
+ crc32: number;
18
+ /** Uncompressed size in bytes */
19
+ uncompressedSize: bigint;
20
+ /** Compressed size in bytes */
21
+ compressedSize: bigint;
22
+ /** Entry information is in ZIP64 format */
23
+ zip64: true;
24
+ }
25
+ export type EntryInfoStandard = {
26
+ [K in keyof EntryInfoZip64]: EntryInfoZip64[K] extends bigint ? number : K extends "zip64" ? false : EntryInfoZip64[K];
27
+ };
28
+ export type EntryInfo = EntryInfoZip64 | EntryInfoStandard;
29
+ export declare class ZipWriter<TIsZip64 extends boolean = false> {
30
+ #private;
31
+ get readable(): ReadableStream<ArrayBufferView<ArrayBufferLike>>;
32
+ get entries(): ReadonlyArray<Readonly<EntryInfo>>;
33
+ /**
34
+ * Wait until all currently queued entries have been written.
35
+ */
36
+ onceQueueEmpty(): Promise<void>;
37
+ /**
38
+ * Create a new entry in the Zip archive. Use the returned
39
+ * entryWriter.writable to write data to the entry. You can await
40
+ * entryWriter.entry() to get the entry info once all data has been written.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * const response = await fetch(imageUrl);
45
+ * response.body!.pipeTo(
46
+ * zipWriter.entry({ name: "path/to/file.png" }).writable
47
+ * );
48
+ * ```
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * const entryWriter = zipWriter.entry({ name: "hello.txt" });
53
+ * const writer = entryWriter.writable.getWriter();
54
+ * await writer.write(
55
+ * new TextEncoder().encode("Hello, World!")
56
+ * );
57
+ * await writer.close();
58
+ * console.log(await entryWriter.entry()); // Entry info
59
+ * ```
60
+ *
61
+ * @param options Entry options
62
+ */
63
+ entry(options: EntryOptions): EntryWriter;
64
+ /**
65
+ * Set the entries of the Zip archive. This can be used to reorder,
66
+ * remove, or rename entries before finalizing the archive.
67
+ *
68
+ * @param entries New entries array
69
+ */
70
+ setEntries(entries: ReadonlyArray<Readonly<EntryInfo>>): void;
71
+ finalize(): Promise<{
72
+ /** Does the archive use ZIP64 format? */
73
+ zip64: boolean;
74
+ /** Total uncompressed size of all entries */
75
+ uncompressedEntriesSize: bigint;
76
+ /** Total compressed size of all entries */
77
+ compressedEntriesSize: bigint;
78
+ /** Total size of the ZIP file */
79
+ fileSize: bigint;
80
+ }>;
81
+ }
82
+ declare class EntryWriter {
83
+ #private;
84
+ /**
85
+ * @param enqueueAndPipe Function that enqueues the entry data readable, pipes it to the Zip stream, and returns a promise that resolves to the entry info once done.
86
+ */
87
+ constructor(enqueueAndPipe: (readable: ReadableStream<Uint8Array<ArrayBuffer>>) => Promise<EntryInfo>);
88
+ /**
89
+ * Writable stream to write entry data to.
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * ReadableStream.from([new TextEncoder().encode("Hello, World!")])
94
+ * .pipeTo(entryWriter.writable);
95
+ * ```
96
+ */
97
+ get writable(): WritableStream<any>;
98
+ /**
99
+ * Get entry info. Resolves once all data has been written to the Zip stream.
100
+ */
101
+ entry(): Promise<EntryInfo>;
102
+ }
103
+ export {};
104
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAeA,MAAM,WAAW,YAAY;IAC3B,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,oBAAoB;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iBAAiB;IACjB,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,wBAAwB;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,4DAA4D;IAC5D,KAAK,CAAC,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c,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,KAC9C,OAAO,CAAC,SAAS,CAAC;IAazB;;;;;;;;OAQG;IACH,IAAI,QAAQ,wBAEX;IAED;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,SAAS,CAAC;CAGlC"}
package/dist/index.js ADDED
@@ -0,0 +1,245 @@
1
+ import { writeZipEntry } from "./write-entry.js";
2
+ import { getCDFH, getEOCDZip64, getEOCDStandard, } from "./write-central-directory.js";
3
+ import { ZIP64_LIMIT } from "./constants.js";
4
+ import { noop } from "./utils.js";
5
+ const BUFFER_SIZE = 16 * 1024; // 16 KB
6
+ const bufferedQueue = new ByteLengthQueuingStrategy({
7
+ highWaterMark: BUFFER_SIZE,
8
+ });
9
+ const unbufferedQueue = { highWaterMark: 0 };
10
+ export class ZipWriter {
11
+ #offset = BigInt(0);
12
+ #zipStream = new TransformStream({
13
+ transform: (chunk, controller) => {
14
+ controller.enqueue(chunk);
15
+ this.#offset += BigInt(chunk.byteLength);
16
+ },
17
+ },
18
+ // Unbuffered on the writable side, we already queue entries
19
+ unbufferedQueue,
20
+ // Readable buffer, so that temporary delays on writable consumers don't
21
+ // block the zip writing.
22
+ bufferedQueue);
23
+ #entries = [];
24
+ #queued = Promise.resolve();
25
+ #entryCount = 0;
26
+ #finalized = false;
27
+ get readable() {
28
+ return this.#zipStream.readable;
29
+ }
30
+ get entries() {
31
+ return this.#entries;
32
+ }
33
+ /**
34
+ * Wait until all currently queued entries have been written.
35
+ */
36
+ async onceQueueEmpty() {
37
+ while (this.#entries.length < this.#entryCount) {
38
+ await this.#queued;
39
+ }
40
+ }
41
+ /**
42
+ * Create a new entry in the Zip archive. Use the returned
43
+ * entryWriter.writable to write data to the entry. You can await
44
+ * entryWriter.entry() to get the entry info once all data has been written.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * const response = await fetch(imageUrl);
49
+ * response.body!.pipeTo(
50
+ * zipWriter.entry({ name: "path/to/file.png" }).writable
51
+ * );
52
+ * ```
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * const entryWriter = zipWriter.entry({ name: "hello.txt" });
57
+ * const writer = entryWriter.writable.getWriter();
58
+ * await writer.write(
59
+ * new TextEncoder().encode("Hello, World!")
60
+ * );
61
+ * await writer.close();
62
+ * console.log(await entryWriter.entry()); // Entry info
63
+ * ```
64
+ *
65
+ * @param options Entry options
66
+ */
67
+ entry(options) {
68
+ if (this.#finalized) {
69
+ throw new TypeError("Cannot add entry after finalize() has been called");
70
+ }
71
+ this.#entryCount++;
72
+ // Capture the previous queue position
73
+ const prevQueued = this.#queued;
74
+ // Create a promise that will be resolved when this entry completes
75
+ let entryDone;
76
+ let entryError;
77
+ this.#queued = new Promise((resolve, reject) => {
78
+ entryDone = resolve;
79
+ entryError = reject;
80
+ });
81
+ // prevent unhandled rejection, but we still want this.#queued to reject
82
+ // when awaited if there's an error
83
+ this.#queued.catch(noop);
84
+ return new EntryWriter(async (readable) => {
85
+ // Wait for previous entry to complete
86
+ await prevQueued;
87
+ const writer = this.#zipStream.writable.getWriter();
88
+ const reader = readable.getReader();
89
+ try {
90
+ const entryInfo = await writeZipEntry({
91
+ writer,
92
+ reader,
93
+ entryOptions: options,
94
+ startOffset: this.#offset,
95
+ });
96
+ this.#entries.push(entryInfo);
97
+ entryDone();
98
+ return entryInfo;
99
+ }
100
+ catch (err) {
101
+ entryError(err);
102
+ await reader.cancel(err);
103
+ // Abort the zip stream - it's corrupted after a partial entry write
104
+ this.#zipStream.writable.abort(err);
105
+ // Don't call entryDone() - leave subsequent entries waiting forever
106
+ // since the zip stream is corrupted
107
+ // This error is handled in the EntryWriter constructor, and used to
108
+ // abort the entry writable stream
109
+ throw err;
110
+ }
111
+ finally {
112
+ reader.releaseLock();
113
+ writer.releaseLock();
114
+ }
115
+ });
116
+ }
117
+ /**
118
+ * Set the entries of the Zip archive. This can be used to reorder,
119
+ * remove, or rename entries before finalizing the archive.
120
+ *
121
+ * @param entries New entries array
122
+ */
123
+ setEntries(entries) {
124
+ const currentEntriesByOffset = new Map();
125
+ for (const entry of this.#entries) {
126
+ currentEntriesByOffset.set(BigInt(entry.startOffset), entry);
127
+ }
128
+ // Entries can't have their offset, crc32, compressed size, or uncompressed
129
+ // size changed, but they can be removed, reordered, or have the name and
130
+ // comment changed.
131
+ for (const entry of entries) {
132
+ const existingEntry = currentEntriesByOffset.get(BigInt(entry.startOffset));
133
+ if (!existingEntry) {
134
+ throw new Error(`Cannot set entries: entry at offset ${entry.startOffset} does not exist`);
135
+ }
136
+ if (existingEntry.crc32 !== entry.crc32) {
137
+ throw new Error(`Cannot set entries: entry at offset ${entry.startOffset} has different CRC32`);
138
+ }
139
+ if (existingEntry.uncompressedSize !== entry.uncompressedSize) {
140
+ throw new Error(`Cannot set entries: entry at offset ${entry.startOffset} has different uncompressed size`);
141
+ }
142
+ if (existingEntry.compressedSize !== entry.compressedSize) {
143
+ throw new Error(`Cannot set entries: entry at offset ${entry.startOffset} has different compressed size`);
144
+ }
145
+ }
146
+ this.#entries = entries.map((entry) => ({ ...entry }));
147
+ }
148
+ async finalize() {
149
+ if (this.#finalized) {
150
+ throw new TypeError("finalize() has already been called");
151
+ }
152
+ this.#finalized = true;
153
+ // We do this as an IIFE to avoid an unhandled error, so that a user can
154
+ // call finalize() without needing to await and catch an error. Any error
155
+ // will be propagated to the stream output, but the user can optionally
156
+ // await finalize() to also see the error.
157
+ const finalizePromise = (async () => {
158
+ await this.onceQueueEmpty();
159
+ // Write central directory headers for all entries
160
+ const centralDirectoryStart = this.#offset;
161
+ const writer = this.#zipStream.writable.getWriter();
162
+ try {
163
+ let entryUsesZip64 = false;
164
+ let uncompressedEntriesSize = BigInt(0);
165
+ let compressedEntriesSize = BigInt(0);
166
+ for (const entry of this.#entries) {
167
+ if (entry.zip64) {
168
+ entryUsesZip64 = true;
169
+ }
170
+ uncompressedEntriesSize += BigInt(entry.uncompressedSize);
171
+ compressedEntriesSize += BigInt(entry.compressedSize);
172
+ await writer.write(getCDFH(entry));
173
+ }
174
+ const centralDirectorySize = this.#offset - centralDirectoryStart;
175
+ // Determine if the archive needs ZIP64 based on entries or central directory
176
+ const eocdNeedsZip64 = this.#entries.length > 0xffff ||
177
+ centralDirectoryStart > ZIP64_LIMIT ||
178
+ centralDirectorySize > ZIP64_LIMIT;
179
+ let eocd;
180
+ if (eocdNeedsZip64) {
181
+ eocd = getEOCDZip64(BigInt(this.#entries.length), centralDirectoryStart, centralDirectorySize);
182
+ }
183
+ else {
184
+ eocd = getEOCDStandard(this.#entries.length, Number(centralDirectoryStart), Number(centralDirectorySize));
185
+ }
186
+ await writer.write(eocd);
187
+ // Close the zip stream
188
+ await writer.close();
189
+ return {
190
+ zip64: eocdNeedsZip64 || entryUsesZip64,
191
+ uncompressedEntriesSize,
192
+ compressedEntriesSize,
193
+ fileSize: this.#offset,
194
+ };
195
+ }
196
+ catch (err) {
197
+ await writer.abort(err);
198
+ throw err;
199
+ }
200
+ finally {
201
+ writer.releaseLock();
202
+ }
203
+ })();
204
+ finalizePromise.catch(noop); // prevent unhandled rejection
205
+ return finalizePromise;
206
+ }
207
+ }
208
+ class EntryWriter {
209
+ // Unbuffered stream to directly pipe to the zip writer
210
+ #entryStream = new TransformStream(undefined, unbufferedQueue, unbufferedQueue);
211
+ #written;
212
+ /**
213
+ * @param enqueueAndPipe Function that enqueues the entry data readable, pipes it to the Zip stream, and returns a promise that resolves to the entry info once done.
214
+ */
215
+ constructor(enqueueAndPipe) {
216
+ // We could try to pass the zipstream writable to EntryWriter, but then
217
+ // EntryWriter would not know when the entry has finished writing, and would
218
+ // not have a way to get the entry info.
219
+ this.#written = enqueueAndPipe(this.#entryStream.readable);
220
+ // abort the writable quickly if there is an error, and ensure we don't
221
+ // throw an uncaught error.
222
+ this.#written.catch((reason) => {
223
+ this.#entryStream.writable.abort(reason);
224
+ });
225
+ }
226
+ /**
227
+ * Writable stream to write entry data to.
228
+ *
229
+ * @example
230
+ * ```ts
231
+ * ReadableStream.from([new TextEncoder().encode("Hello, World!")])
232
+ * .pipeTo(entryWriter.writable);
233
+ * ```
234
+ */
235
+ get writable() {
236
+ return this.#entryStream.writable;
237
+ }
238
+ /**
239
+ * Get entry info. Resolves once all data has been written to the Zip stream.
240
+ */
241
+ async entry() {
242
+ return this.#written;
243
+ }
244
+ }
245
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EACL,OAAO,EACP,YAAY,EACZ,eAAe,GAChB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,MAAM,WAAW,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,QAAQ;AACvC,MAAM,aAAa,GAAG,IAAI,yBAAyB,CAAC;IAClD,aAAa,EAAE,WAAW;CAC3B,CAAC,CAAC;AACH,MAAM,eAAe,GAAG,EAAE,aAAa,EAAE,CAAC,EAAE,CAAC;AAsC7C,MAAM,OAAO,SAAS;IACpB,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IACpB,UAAU,GAAG,IAAI,eAAe,CAC9B;QACE,SAAS,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE;YAC/B,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAC1B,IAAI,CAAC,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAC3C,CAAC;KACF;IACD,4DAA4D;IAC5D,eAAe;IACf,wEAAwE;IACxE,yBAAyB;IACzB,aAAa,CACd,CAAC;IACF,QAAQ,GAAgB,EAAE,CAAC;IAC3B,OAAO,GAAqB,OAAO,CAAC,OAAO,EAAE,CAAC;IAC9C,WAAW,GAAG,CAAC,CAAC;IAChB,UAAU,GAAG,KAAK,CAA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,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,MAAM,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACxB,MAAM,GAAG,CAAC;YACZ,CAAC;oBAAS,CAAC;gBACT,MAAM,CAAC,WAAW,EAAE,CAAC;YACvB,CAAC;QACH,CAAC,CAAC,EAAE,CAAC;QACL,eAAe,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,8BAA8B;QAC3D,OAAO,eAAe,CAAC;IACzB,CAAC;CACF;AAED,MAAM,WAAW;IACf,uDAAuD;IACvD,YAAY,GAAG,IAAI,eAAe,CAChC,SAAS,EACT,eAAe,EACf,eAAe,CAChB,CAAC;IACF,QAAQ,CAAqB;IAE7B;;OAEG;IACH,YACE,cAEuB;QAEvB,uEAAuE;QACvE,4EAA4E;QAC5E,wCAAwC;QACxC,IAAI,CAAC,QAAQ,GAAG,cAAc,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;QAC3D,uEAAuE;QACvE,2BAA2B;QAC3B,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE;YAC7B,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;OAQG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC;IACpC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;CACF"}
@@ -0,0 +1,4 @@
1
+ export declare function getDosTime(date: Date): number;
2
+ export declare function getDosDate(date: Date): number;
3
+ export declare function noop(): void;
4
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAM7C;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAM7C;AAED,wBAAgB,IAAI,SAAK"}
package/dist/utils.js ADDED
@@ -0,0 +1,12 @@
1
+ export function getDosTime(date) {
2
+ return ((date.getHours() << 11) |
3
+ (date.getMinutes() << 5) |
4
+ (date.getSeconds() >> 1));
5
+ }
6
+ export function getDosDate(date) {
7
+ return (((date.getFullYear() - 1980) << 9) |
8
+ ((date.getMonth() + 1) << 5) |
9
+ date.getDate());
10
+ }
11
+ export function noop() { }
12
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,UAAU,CAAC,IAAU;IACnC,OAAO,CACL,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC;QACvB,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QACxB,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,CACzB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,IAAU;IACnC,OAAO,CACL,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;QAClC,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;QAC5B,IAAI,CAAC,OAAO,EAAE,CACf,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,IAAI,KAAI,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { EntryInfo } from "./index.js";
2
+ /**
3
+ * Generate the Central Directory File Header for the given entry info.
4
+ */
5
+ export declare function getCDFH(entryInfo: EntryInfo): Uint8Array<ArrayBuffer>;
6
+ /**
7
+ * Generate the End of Central Directory record with zip64 support.
8
+ */
9
+ export declare function getEOCDStandard(entriesCount: number, centralDirectoryOffset: number, centralDirectorySize: number): Uint8Array<ArrayBuffer>;
10
+ /**
11
+ * Generate the ZIP64 End of Central Directory record.
12
+ */
13
+ export declare function getEOCDZip64(entriesCount: bigint, centralDirectoryOffset: bigint, centralDirectorySize: bigint): Uint8Array<ArrayBuffer>;
14
+ //# sourceMappingURL=write-central-directory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write-central-directory.d.ts","sourceRoot":"","sources":["../src/write-central-directory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAqC,MAAM,YAAY,CAAC;AAsB/E;;GAEG;AACH,wBAAgB,OAAO,CAAC,SAAS,EAAE,SAAS,GAAG,UAAU,CAAC,WAAW,CAAC,CAMrE;AAsND;;GAEG;AACH,wBAAgB,eAAe,CAC7B,YAAY,EAAE,MAAM,EACpB,sBAAsB,EAAE,MAAM,EAC9B,oBAAoB,EAAE,MAAM,GAC3B,UAAU,CAAC,WAAW,CAAC,CAsCzB;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,YAAY,EAAE,MAAM,EACpB,sBAAsB,EAAE,MAAM,EAC9B,oBAAoB,EAAE,MAAM,GAC3B,UAAU,CAAC,WAAW,CAAC,CAyGzB"}