zip-writer 1.0.0 → 1.1.0

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 (46) hide show
  1. package/README.md +427 -0
  2. package/dist/constants.d.ts +21 -0
  3. package/dist/constants.d.ts.map +1 -0
  4. package/{src/constants.ts → dist/constants.js} +1 -5
  5. package/dist/constants.js.map +1 -0
  6. package/{src/crc.ts → dist/crc-browser.d.ts} +2 -39
  7. package/dist/crc-browser.d.ts.map +1 -0
  8. package/dist/crc-browser.js +82 -0
  9. package/dist/crc-browser.js.map +1 -0
  10. package/dist/crc-node.d.ts +2 -0
  11. package/dist/crc-node.d.ts.map +1 -0
  12. package/dist/crc-node.js +3 -0
  13. package/dist/crc-node.js.map +1 -0
  14. package/dist/index.d.ts +138 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +298 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/utils.d.ts +4 -0
  19. package/dist/utils.d.ts.map +1 -0
  20. package/dist/utils.js +12 -0
  21. package/dist/utils.js.map +1 -0
  22. package/dist/write-central-directory.d.ts +14 -0
  23. package/dist/write-central-directory.d.ts.map +1 -0
  24. package/dist/write-central-directory.js +279 -0
  25. package/dist/write-central-directory.js.map +1 -0
  26. package/dist/write-entry.d.ts +26 -0
  27. package/dist/write-entry.d.ts.map +1 -0
  28. package/dist/write-entry.js +172 -0
  29. package/dist/write-entry.js.map +1 -0
  30. package/package.json +32 -5
  31. package/.claude/settings.local.json +0 -11
  32. package/.github/workflows/test.yml +0 -36
  33. package/.husky/pre-commit +0 -1
  34. package/eslint.config.mjs +0 -9
  35. package/src/crc-lookup.ts +0 -27
  36. package/src/index.ts +0 -342
  37. package/src/utils.ts +0 -17
  38. package/src/write-central-directory.ts +0 -405
  39. package/src/write-entry.ts +0 -246
  40. package/test/commands.ts +0 -47
  41. package/test/crc.test.ts +0 -45
  42. package/test/integration.test.ts +0 -483
  43. package/test/utils.ts +0 -40
  44. package/tsconfig.json +0 -36
  45. package/tsconfig.node.json +0 -10
  46. package/vitest.config.ts +0 -46
package/README.md ADDED
@@ -0,0 +1,427 @@
1
+ # zip-writable
2
+
3
+ A modern streaming ZIP archive writer for JavaScript that uses the
4
+ [Web Streams API](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API)
5
+ and
6
+ [Compression Streams API](https://developer.mozilla.org/en-US/docs/Web/API/Compression_Streams_API).
7
+
8
+ ## Features
9
+
10
+ - **Streaming API** - Write ZIP archives using Web Streams
11
+ - **Memory efficient** - Process large files without loading them entirely into
12
+ memory
13
+ - **ZIP64 support** - Automatic handling of large files and archives
14
+ - **Modern JavaScript** - Built with TypeScript, uses native Web Streams API
15
+ - **Flexible** - Reorder, rename, or remove entries before finalizing
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install zip-writable
21
+ ```
22
+
23
+ ## Basic Usage
24
+
25
+ ```ts
26
+ import { ZipWriter } from "zip-writable";
27
+
28
+ const zipWriter = new ZipWriter();
29
+
30
+ // Pipe the ZIP output somewhere
31
+ zipWriter.readable.pipeTo(writableStream);
32
+
33
+ // Add entries to the ZIP
34
+ const entryWriter = zipWriter.createEntryStream({ name: "hello.txt" });
35
+ const writer = entryWriter.writable.getWriter();
36
+ await writer.write(new TextEncoder().encode("Hello, World!"));
37
+ await writer.close();
38
+
39
+ // Get entry info after writing
40
+ const info = await entryWriter.getEntryInfo();
41
+ console.log(info);
42
+
43
+ // Finalize the ZIP archive
44
+ await zipWriter.finalize();
45
+ ```
46
+
47
+ ## API Reference
48
+
49
+ ### `ZipWriter`
50
+
51
+ The main class for creating ZIP archives.
52
+
53
+ #### Constructor
54
+
55
+ ##### `new ZipWriter(options?)`
56
+
57
+ **Parameters:**
58
+
59
+ - `options.crc32?: (data: Uint8Array, value?: number) => number` - Optional
60
+ CRC32 function to use. Defaults to `zlib.crc32` on Node.js and a pure
61
+ JavaScript implementation in browsers.
62
+
63
+ #### Properties
64
+
65
+ ##### `readable: ReadableStream<Uint8Array>`
66
+
67
+ The readable stream containing the ZIP archive data. Pipe this to a file, HTTP
68
+ response, or any other writable destination.
69
+
70
+ ```ts
71
+ // Save to file (Node.js with fs/promises)
72
+ import { createWriteStream } from "fs";
73
+ import { Writable } from "stream";
74
+
75
+ zipWriter.readable.pipeTo(Writable.toWeb(createWriteStream("archive.zip")));
76
+
77
+ // Send as HTTP response (in a web server)
78
+ return new Response(zipWriter.readable, {
79
+ headers: {
80
+ "Content-Type": "application/zip",
81
+ "Content-Disposition": 'attachment; filename="archive.zip"',
82
+ },
83
+ });
84
+ ```
85
+
86
+ ##### `entries: ReadonlyArray<Readonly<EntryInfo>>`
87
+
88
+ Array of all entries that have been written to the archive. Each entry contains
89
+ metadata like size, CRC32, compression info, etc.
90
+
91
+ #### Methods
92
+
93
+ ##### `createEntry(data: Uint8Array, options: EntryOptions): Promise<EntryInfo>`
94
+
95
+ Convenience method to add a buffer as an entry to the zip archive. Returns a
96
+ promise that resolves to the entry info once written. For more efficient
97
+ streaming writes, use `createEntryStream()`.
98
+
99
+ **Parameters:**
100
+
101
+ - `data: Uint8Array` - Entry data to write
102
+ - `options.name: string` - Entry name including internal path (required)
103
+ - `options.comment?: string` - Entry comment
104
+ - `options.date?: Date` - Entry date (defaults to current date)
105
+ - `options.mode?: number` - Entry permissions (Unix-style mode)
106
+ - `options.store?: boolean` - Set to `true` to disable compression (defaults to
107
+ `false`, using DEFLATE compression)
108
+
109
+ **Example:**
110
+
111
+ ```ts
112
+ const data = new TextEncoder().encode("Hello, World!");
113
+ const entryInfo = await zipWriter.createEntry(data, { name: "hello.txt" });
114
+ console.log(entryInfo);
115
+ ```
116
+
117
+ ##### `createEntryStream(options: EntryOptions): EntryWriter`
118
+
119
+ Create a new entry in the ZIP archive. Returns an `EntryWriter` that you can
120
+ write data to via streams.
121
+
122
+ **Parameters:**
123
+
124
+ - `options.name: string` - Entry name including internal path (required)
125
+ - `options.comment?: string` - Entry comment
126
+ - `options.date?: Date` - Entry date (defaults to current date)
127
+ - `options.mode?: number` - Entry permissions (Unix-style mode)
128
+ - `options.store?: boolean` - Set to `true` to disable compression (defaults to
129
+ `false`, using DEFLATE compression)
130
+
131
+ **Examples:**
132
+
133
+ ```ts
134
+ // Simple text file
135
+ const entry = zipWriter.createEntryStream({ name: "readme.txt" });
136
+ const writer = entry.writable.getWriter();
137
+ await writer.write(new TextEncoder().encode("Hello!"));
138
+ await writer.close();
139
+
140
+ // Stream a fetch response
141
+ const response = await fetch(imageUrl);
142
+ response.body.pipeTo(
143
+ zipWriter.createEntryStream({ name: "images/photo.jpg" }).writable,
144
+ );
145
+
146
+ // With custom date and permissions
147
+ zipWriter.createEntryStream({
148
+ name: "script.sh",
149
+ date: new Date("2024-01-01"),
150
+ mode: 0o755, // executable
151
+ }).writable;
152
+
153
+ // Disable compression for already-compressed files
154
+ zipWriter.createEntryStream({
155
+ name: "video.mp4",
156
+ store: true, // no compression
157
+ }).writable;
158
+ ```
159
+
160
+ ##### `onceQueueEmpty(): Promise<void>`
161
+
162
+ Wait until all currently queued entries have been written. Useful when you need
163
+ to ensure entries are complete before continuing.
164
+
165
+ ```ts
166
+ // Add multiple entries
167
+ zipWriter.createEntryStream({ name: "file1.txt" }).writable;
168
+ zipWriter.createEntryStream({ name: "file2.txt" }).writable;
169
+
170
+ // Wait for all to complete
171
+ await zipWriter.onceQueueEmpty();
172
+ console.log(`Wrote ${zipWriter.entries.length} entries`);
173
+ ```
174
+
175
+ ##### `finalize(options?): Promise<{ zip64: boolean, uncompressedEntriesSize: bigint, compressedEntriesSize: bigint, fileSize: bigint }>`
176
+
177
+ Finalize the ZIP archive by writing the central directory and end of central
178
+ directory records. This must be called after all entries have been added. This
179
+ will await any pending entries to finish writing before finalizing.
180
+
181
+ **Parameters:**
182
+
183
+ - `options.entries?: ReadonlyArray<Readonly<EntryInfo>>` - (Advanced) Override
184
+ the entries to write in the central directory. This can be used to reorder,
185
+ remove, or rename entries before finalizing the archive. You cannot change the
186
+ offset, CRC32, compressed size, or uncompressed size of entries - only the
187
+ name, comment, date, and order.
188
+
189
+ **Returns:**
190
+
191
+ - `zip64: boolean` - Whether the archive uses ZIP64 format
192
+ - `uncompressedEntriesSize: bigint` - Total uncompressed size of all entries
193
+ - `compressedEntriesSize: bigint` - Total compressed size of all entries
194
+ - `fileSize: bigint` - Total size of the ZIP file
195
+
196
+ ```ts
197
+ const result = await zipWriter.finalize();
198
+ console.log(`Created ${result.zip64 ? "ZIP64" : "standard"} archive`);
199
+ console.log(`File size: ${result.fileSize} bytes`);
200
+ console.log(
201
+ `Compression ratio: ${Number(result.compressedEntriesSize) / Number(result.uncompressedEntriesSize)}`,
202
+ );
203
+ ```
204
+
205
+ **Example with entries option:**
206
+
207
+ ```ts
208
+ // Wait for all entries to be written
209
+ await zipWriter.onceQueueEmpty();
210
+
211
+ // Get current entries and modify them
212
+ const entries = [...zipWriter.entries];
213
+
214
+ // Remove an entry
215
+ const filtered = entries.filter((e) => e.name !== "temp.txt");
216
+
217
+ // Rename entries
218
+ const renamed = entries.map((e) => ({
219
+ ...e,
220
+ name: e.name.replace(/^old\//, "new/"),
221
+ }));
222
+
223
+ // Sort entries alphabetically
224
+ const sorted = [...entries].sort((a, b) => a.name.localeCompare(b.name));
225
+
226
+ // Finalize with modified entries
227
+ await zipWriter.finalize({ entries: sorted });
228
+ ```
229
+
230
+ ### `EntryWriter`
231
+
232
+ Returned by `ZipWriter.createEntryStream()`. Provides a writable stream to write
233
+ entry data.
234
+
235
+ #### Properties
236
+
237
+ ##### `writable: WritableStream<Uint8Array>`
238
+
239
+ The writable stream to write entry data to. Close this stream when done writing.
240
+
241
+ ```ts
242
+ const entryWriter = zipWriter.createEntryStream({ name: "data.txt" });
243
+
244
+ // Using a writer
245
+ const writer = entryWriter.writable.getWriter();
246
+ await writer.write(new TextEncoder().encode("chunk 1"));
247
+ await writer.write(new TextEncoder().encode("chunk 2"));
248
+ await writer.close();
249
+
250
+ // Using pipeTo
251
+ someReadableStream.pipeTo(entryWriter.writable);
252
+ ```
253
+
254
+ #### Methods
255
+
256
+ ##### `getEntryInfo(): Promise<EntryInfo>`
257
+
258
+ Get entry info. Resolves once all data has been written to the ZIP stream.
259
+
260
+ **Returns `EntryInfo`:**
261
+
262
+ - `name: string` - Entry name
263
+ - `comment?: string` - Entry comment
264
+ - `date?: Date` - Entry date
265
+ - `mode?: number` - Entry permissions
266
+ - `store?: boolean` - Whether compression was disabled
267
+ - `startOffset: bigint | number` - Byte offset in the archive
268
+ - `crc32: number` - CRC32 checksum
269
+ - `uncompressedSize: bigint | number` - Uncompressed size in bytes
270
+ - `compressedSize: bigint | number` - Compressed size in bytes
271
+ - `zip64: boolean` - Whether this entry uses ZIP64 format
272
+
273
+ ```ts
274
+ const entryWriter = zipWriter.createEntryStream({ name: "test.txt" });
275
+ await someStream.pipeTo(entryWriter.writable);
276
+
277
+ const info = await entryWriter.getEntryInfo();
278
+ console.log(
279
+ `Wrote ${info.name}: ${info.uncompressedSize} bytes (compressed to ${info.compressedSize})`,
280
+ );
281
+ ```
282
+
283
+ ## Complete Example
284
+
285
+ ```ts
286
+ import { ZipWriter } from "zip-writable";
287
+ import { createWriteStream } from "fs";
288
+ import { Writable } from "stream";
289
+
290
+ async function createZip() {
291
+ const zipWriter = new ZipWriter();
292
+
293
+ // Pipe output to file
294
+ const fileStream = Writable.toWeb(createWriteStream("output.zip"));
295
+ zipWriter.readable.pipeTo(fileStream);
296
+
297
+ // Add a text file using createEntry
298
+ const data1 = new TextEncoder().encode("This is a readme");
299
+ await zipWriter.createEntry(data1, { name: "readme.txt" });
300
+
301
+ // Add files from URLs using createEntryStream
302
+ const imageResponse = await fetch("https://example.com/image.png");
303
+ await imageResponse.body.pipeTo(
304
+ zipWriter.createEntryStream({ name: "images/photo.png" }).writable,
305
+ );
306
+
307
+ // Add a JSON file using createEntry
308
+ const data = { hello: "world" };
309
+ const jsonData = new TextEncoder().encode(JSON.stringify(data, null, 2));
310
+ await zipWriter.createEntry(jsonData, { name: "data.json" });
311
+
312
+ // Wait for all entries and check results
313
+ await zipWriter.onceQueueEmpty();
314
+ console.log(`Added ${zipWriter.entries.length} entries`);
315
+
316
+ // Finalize the archive
317
+ const result = await zipWriter.finalize();
318
+ console.log(`Created archive: ${result.fileSize} bytes`);
319
+ }
320
+
321
+ createZip().catch(console.error);
322
+ ```
323
+
324
+ ## Browser Usage
325
+
326
+ ```ts
327
+ // Create a ZIP and trigger download
328
+ const zipWriter = new ZipWriter();
329
+
330
+ // Add entries...
331
+ const data = new TextEncoder().encode("Hello");
332
+ zipWriter
333
+ .createEntry(data, { name: "file.txt" })
334
+ .then(() => zipWriter.finalize());
335
+
336
+ // Create download link
337
+ const blob = await new Response(zipWriter.readable).blob();
338
+ const url = URL.createObjectURL(blob);
339
+ const a = document.createElement("a");
340
+ a.href = url;
341
+ a.download = "archive.zip";
342
+ a.click();
343
+ URL.revokeObjectURL(url);
344
+ ```
345
+
346
+ ## Benchmarks
347
+
348
+ Run using `npm run bench`. On a MacBook Pro (M2 Pro, 2023), Node.js 20.19.0:
349
+
350
+ ### Small files (10 × 10KB)
351
+
352
+ | Library | ops/sec | Relative Speed |
353
+ | ----------------------------- | ------- | -------------- |
354
+ | zip-writable (@node-rs/crc32) | 721.94 | **fastest** |
355
+ | zip-writable | 674.57 | 1.07x slower |
356
+ | zip-writable (js crc32) | 659.90 | 1.09x slower |
357
+ | fflate | 553.00 | 1.31x slower |
358
+ | archiver | 338.14 | 2.14x slower |
359
+ | @zip.js/zip.js | 279.19 | 2.59x slower |
360
+
361
+ ### Medium files (100 × 100KB)
362
+
363
+ | Library | ops/sec | Relative Speed |
364
+ | ----------------------------- | ------- | -------------- |
365
+ | zip-writable | 23.91 | **fastest** |
366
+ | zip-writable (@node-rs/crc32) | 22.91 | 1.04x slower |
367
+ | zip-writable (js crc32) | 18.93 | 1.26x slower |
368
+ | archiver | 18.10 | 1.32x slower |
369
+ | @zip.js/zip.js | 11.65 | 2.05x slower |
370
+ | fflate | 10.27 | 2.33x slower |
371
+
372
+ ### Large files (5 × 10MB)
373
+
374
+ | Library | ops/sec | Relative Speed |
375
+ | ----------------------------- | ------- | -------------- |
376
+ | zip-writable | 7.22 | **fastest** |
377
+ | zip-writable (@node-rs/crc32) | 6.78 | 1.06x slower |
378
+ | archiver | 5.65 | 1.28x slower |
379
+ | zip-writable (js crc32) | 4.82 | 1.50x slower |
380
+ | fflate | 4.20 | 1.72x slower |
381
+ | @zip.js/zip.js | 4.00 | 1.81x slower |
382
+
383
+ ### Many files (1000 × 1KB)
384
+
385
+ | Library | ops/sec | Relative Speed |
386
+ | ----------------------------- | ------- | -------------- |
387
+ | fflate | 10.08 | **fastest** |
388
+ | zip-writable | 6.89 | 1.46x slower |
389
+ | zip-writable (@node-rs/crc32) | 5.94 | 1.70x slower |
390
+ | zip-writable (js crc32) | 5.63 | 1.79x slower |
391
+ | archiver | 4.98 | 2.02x slower |
392
+ | @zip.js/zip.js | 2.93 | 3.44x slower |
393
+
394
+ Note: These benchmarks vary quite a bit, and they aren't an indication that any
395
+ library is "better" than any other. For ZipWriter, these exist as a check to
396
+ ensure that performance isn't significantly worse than other libraries.
397
+
398
+ ## ZIP64 Support
399
+
400
+ The library automatically uses ZIP64 format when needed:
401
+
402
+ - Archives with more than 65,535 entries
403
+ - Files larger than 4GB
404
+ - Central directory larger than 4GB
405
+ - Central directory offset greater than 4GB
406
+
407
+ No special configuration is needed - it's handled automatically.
408
+
409
+ ## Error Handling
410
+
411
+ ```ts
412
+ try {
413
+ const entryWriter = zipWriter.entry({ name: "test.txt" });
414
+ await someStream.pipeTo(entryWriter.writable);
415
+ await entryWriter.getEntryInfo();
416
+ } catch (error) {
417
+ console.error("Failed to write entry:", error);
418
+ // The ZIP stream is aborted on error - cannot add more entries
419
+ }
420
+ ```
421
+
422
+ Once an error occurs during entry writing, the ZIP stream is corrupted and
423
+ cannot be recovered. You must create a new `ZipWriter` instance.
424
+
425
+ ## License
426
+
427
+ MIT
@@ -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"}
@@ -20,9 +20,6 @@
20
20
  * misrepresented as being the original software.
21
21
  * 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-browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crc-browser.d.ts","sourceRoot":"","sources":["../src/crc-browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AA8BH;;;;;;;;GAQG;AACH,wBAAgB,KAAK,CACnB,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,EAC7B,KAAK,GAAE,MAAU,GAChB,MAAM,CAgCR"}
@@ -0,0 +1,82 @@
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
+ /**
24
+ * From https://github.com/holepunchto/crc-universal/blob/main/lookup.js
25
+ * Licensed under Apache-2.0
26
+ */
27
+ const lookup = new Array(16);
28
+ for (let i = 0; i < 16; i++) {
29
+ lookup[i] = new Uint32Array(0x100);
30
+ }
31
+ for (let i = 0; i <= 0xff; i++) {
32
+ let crc = i;
33
+ for (let j = 0; j < 8; j++) {
34
+ crc = (crc >>> 1) ^ ((crc & 1) * 0xedb88320);
35
+ }
36
+ lookup[0][i] = crc;
37
+ }
38
+ for (let i = 0; i <= 0xff; i++) {
39
+ for (let j = 1; j < 16; j++) {
40
+ lookup[j][i] =
41
+ (lookup[j - 1][i] >>> 8) ^ lookup[0][lookup[j - 1][i] & 0xff];
42
+ }
43
+ }
44
+ /**
45
+ * Computes a 32-bit Cyclic Redundancy Check checksum of data. If value is
46
+ * specified, it is used as the starting value of the checksum, otherwise, 0 is
47
+ * used as the starting value.
48
+ *
49
+ * @param data - The input data to compute the checksum for.
50
+ * @param value - An optional starting value. It must be a 32-bit unsigned integer. Default: 0
51
+ * @returns The computed CRC32 checksum.
52
+ */
53
+ export function crc32(data, value = 0) {
54
+ let crc = ~value;
55
+ let i = 0;
56
+ let length = data.byteLength;
57
+ while (length >= 16) {
58
+ crc =
59
+ lookup[15][data[i++] ^ (crc & 0xff)] ^
60
+ lookup[14][data[i++] ^ ((crc >>> 8) & 0xff)] ^
61
+ lookup[13][data[i++] ^ ((crc >>> 16) & 0xff)] ^
62
+ lookup[12][data[i++] ^ (crc >>> 24)] ^
63
+ lookup[11][data[i++]] ^
64
+ lookup[10][data[i++]] ^
65
+ lookup[9][data[i++]] ^
66
+ lookup[8][data[i++]] ^
67
+ lookup[7][data[i++]] ^
68
+ lookup[6][data[i++]] ^
69
+ lookup[5][data[i++]] ^
70
+ lookup[4][data[i++]] ^
71
+ lookup[3][data[i++]] ^
72
+ lookup[2][data[i++]] ^
73
+ lookup[1][data[i++]] ^
74
+ lookup[0][data[i++]];
75
+ length -= 16;
76
+ }
77
+ while (length-- > 0) {
78
+ crc = (crc >>> 8) ^ lookup[0][(crc & 0xff) ^ data[i++]];
79
+ }
80
+ return ~crc >>> 0;
81
+ }
82
+ //# sourceMappingURL=crc-browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crc-browser.js","sourceRoot":"","sources":["../src/crc-browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH;;;GAGG;AAEH,MAAM,MAAM,GAAG,IAAI,KAAK,CAA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CAAC,CAAC;gBACpB,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC;gBACpB,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC;gBACpB,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAEvB,MAAM,IAAI,EAAE,CAAC;IACf,CAAC;IAED,OAAO,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;QACpB,GAAG,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC;AACpB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { crc32 } from "node:zlib";
2
+ //# sourceMappingURL=crc-node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crc-node.d.ts","sourceRoot":"","sources":["../src/crc-node.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,3 @@
1
+ // @ts-nocheck
2
+ export { crc32 } from "node:zlib";
3
+ //# sourceMappingURL=crc-node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crc-node.js","sourceRoot":"","sources":["../src/crc-node.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC"}