Generate ZIP files in vanilla JavaScript — lightweight, chainable, and dependency-free.
- 📦 Create ZIP files from strings, JSON, ArrayBuffer, or base64.
- 🔗 Add files from URLs with optional progress tracking.
- ⚡ Pure vanilla JavaScript, zero dependencies.
- 🧱 Fluent, chainable API for building archives.
- 🔒 Supports compression (Deflate) if the browser supports it.
- 📊 Optional progress callback for both individual files and total ZIP.
npm install @kitmodule/kitzip<script src="https://unpkg.com/@kitmodule/kitzip/dist/kitzip.min.js"></script>const initialFiles = [
{ name: 'a.txt', content: 'Hello' },
{ name: 'b.txt', content: 'World' }
];
const zip = new KitZip(initialFiles, { compress: true });
await zip.download('init-files.zip');✅ Convenient if you already have a list of files.
const zip = new KitZip({ compress: false }); // empty, no compression
zip.add('file1.txt', 'Hello World!');
zip.add('file2.json', JSON.stringify({ version: 4 }));
// Add file from URL
await zip.addURL('https://example.com/file.txt', 'remote.txt');
await zip.download('add-method.zip');✅ Flexible for dynamic files, e.g., fetched from APIs or user input.
await kitZip([
{ name: 'x.txt', content: 'X content' },
{ name: 'y.txt', content: 'Y content' }
], 'shortcut.zip');✅ Short and simple: just pass a file array and target ZIP filename.
const files = [
{ name: 'a.txt', content: 'A' }
];
const zip = new KitZip(files, { compress: true });
// Add a new file with custom compression
zip.add('b.txt', 'B content', { compress: false });
// Track progress
zip.setProgressHandler((percent, info) => console.log(percent, info));
await zip.download('mixed.zip');✅ Useful for mixed compression settings or tracking ZIP progress.
| Param | Type | Description | |
|---|---|---|---|
files |
Array | Optional array of initial files { name, content, compress? } |
|
options |
Object | `{ compress: true | false }Defaulttrue` |
| Method | Description | Example |
|---|---|---|
.add(name, content) |
Add a file (string, JSON, ArrayBuffer, base64) | .add('hello.txt', 'Hello') |
.addURL(url, name, opts) |
Add a file from a URL with optional onProgress callback |
.addURL('file.txt', 'file.txt') |
.setCompression(bool) |
Enable/disable compression for following files | .setCompression(false) |
.setProgressHandler(fn) |
Callback (percent, info) for total progress |
.setProgressHandler(console.log) |
.download(filename) |
Generate ZIP Blob and trigger download | .download('archive.zip') |
.createStream(writer) |
Stream ZIP to a custom writer with write(chunk) |
.createStream(customWriter) |
kitZip(files, filename) |
Shortcut to create and download ZIP from file array | kitZip([{name:'a',content:'1'}],'a.zip') |
const zip = new KitZip();
zip.add('hello.txt', 'Hello World!');
await zip.download('demo.zip');Output ZIP demo.zip contains:
hello.txt
readme.md
data.json
If you find this library useful, you can support me:
Released under the MIT License © 2025 Huỳnh Nhân Quốc · Open Source @Kit Module