@teamlor/browser-zip
v0.1.0
Published
A micro library for creating ZIP files in the browser
Readme
browser-zip
A micro library for creating ZIP files in the browser.
Installation
bun add @teamlor/browser-zip
# or
npm install @teamlor/browser-zipUsage
import { ZipBuilder, downloadBlob } from '@teamlor/browser-zip';
const blob = await new ZipBuilder()
.add('hello.txt', 'Hello, world!')
.add('data/config.json', JSON.stringify({ key: 'value' }))
.add('image.png', someBlob) // Blob, Uint8Array, or string
.blob();
// Trigger browser download
downloadBlob(blob, 'archive.zip');API
ZipBuilder
Builds a ZIP archive from text, binary, or blob content.
const builder = new ZipBuilder();
builder.add(name: string, content: string | Uint8Array | Blob): this;
builder.blob(): Promise<Blob>;add(name, content)— Add a file to the archive. Acceptsstring,Uint8Array, orBlob. Returnsthisfor chaining.blob()— Produce the ZIP as aBlobwith typeapplication/zip. Returns aPromiseto resolve any pending Blob reads.
downloadBlob(blob, filename, contentType?)
Triggers a browser file download.
| Parameter | Type | Default | Description |
| ------------- | -------- | ------------------- | -------------------------- |
| blob | Blob | | The blob to download |
| filename | string | | Suggested filename |
| contentType | string | 'application/zip' | MIME type for the download |
Browser Usage (CDN)
<script type="module">
import { ZipBuilder, downloadBlob } from './index.bundle.js';
const blob = await new ZipBuilder().add('note.txt', 'Hello from the browser!').blob();
downloadBlob(blob, 'notes.zip');
</script>License
MIT
