|
10 | 10 | LiteJS Zip – [![Coverage][1]][2] [![Size][3]][4] [![Buy Me A Tea][5]][6] |
11 | 11 | ========== |
12 | 12 |
|
13 | | -Dependency-free JavaScript library for creating ZIP files (~1.2KB) in Browser or Server. |
14 | | -Uses the CompressionStream API if available; otherwise will generate uncompressed ZIP. |
| 13 | +Lightweight (~1.2KB) ZIP file creator for Browser and Node.js. No dependencies. |
| 14 | +Uses the CompressionStream API when available; otherwise will generate uncompressed ZIP. |
| 15 | + |
| 16 | + |
| 17 | +createZip(files [, options] [, callback]) |
| 18 | + |
| 19 | + - files: Array of `{name, content[, time]}` |
| 20 | + - options: `{ deflate: deflateRawSync }` (optional custom deflater makes ZIP creation synchronous) |
| 21 | + - callback: Optional `(err, zip)` callback |
| 22 | + |
| 23 | +Returns a `Promise<Uint8Array>`, or invokes provided `callback`, or the ZIP synchronously when using a custom deflater. |
15 | 24 |
|
16 | 25 |
|
17 | 26 | Examples |
18 | 27 | -------- |
19 | 28 |
|
20 | 29 | ```javascript |
21 | | -const { createZip } = require("@litejs/zip"); |
22 | | -const fileAsUint8Array = await createZip([ |
| 30 | +const { createZip } = require("@litejs/zip") |
| 31 | + |
| 32 | +// Async usage |
| 33 | +const zipUint8Array = await createZip([ |
23 | 34 | { name: "file-a.txt", content: "Some content" }, |
24 | 35 | { name: "dir/file-b.txt", content: Uint8Array.from("012"), time: new Date(2020, 1, 21) }, |
25 | 36 | ]) |
| 37 | + |
| 38 | +// Callback style |
| 39 | +createZip(files, (err, zipUint8Array) => { |
| 40 | + // Handle ZIP file content |
| 41 | +}) |
| 42 | + |
| 43 | +// With custom deflate runs synchronously |
| 44 | +const zlib = require("zlib") |
| 45 | +const zipInSync = createZip(files, { deflate: zlib.deflateRawSync }) |
26 | 46 | ``` |
27 | 47 |
|
28 | 48 | ## Contributing |
|
0 commit comments