Lightweight (~1.3KB) ZIP file creator for Browser and Node.js. No dependencies.
Uses the CompressionStream API if available; otherwise uses provided deflater or creates an uncompressed ZIP.
createZip(files [, options] [, callback])
- files: Array of
{name, content[, time]} - options:
{ deflate: deflateRawSync, comment: 'Comment for a file' }(optional custom deflater makes ZIP creation synchronous) - callback: Optional
(err, zip)callback
Returns a Promise<Uint8Array>, or invokes provided callback, or the ZIP synchronously when using a custom deflater.
const { createZip } = require("@litejs/zip")
// Async usage
const zipUint8Array = await createZip([
{ name: "file-a.txt", content: "Some content" },
{ name: "dir/file-b.txt", content: Uint8Array.from("012"), time: new Date(2020, 1, 21) },
])
// Callback style
createZip(files, { comment: "Some comment for a zip file" }, (err, zipUint8Array) => {
// Handle ZIP file content
})
// With custom deflate runs synchronously
const zlib = require("zlib")
const zipInSync = createZip(files, { deflate: zlib.deflateRawSync })Follow Coding Style Guide,
run tests npm install; npm test.
Copyright (c) 2023-2025 Lauri Rooden <lauri@rooden.ee>
MIT License | GitHub repo | npm package | Buy Me A Tea