Introduction
JSZip lets developers create, read, and modify ZIP archives entirely in JavaScript. It runs in the browser without server-side processing, enabling features like client-side file bundling, in-memory archive inspection, and offline export of multi-file downloads—all with a clean promise-based API.
What JSZip Does
- Creates ZIP archives from strings, blobs, array buffers, and typed arrays
- Reads and extracts contents from existing ZIP files
- Supports nested folder structures within archives
- Generates output as Blob, ArrayBuffer, Uint8Array, base64, or Node.js Buffer
- Handles DEFLATE compression with configurable compression level
Architecture Overview
JSZip maintains an in-memory tree of entries representing files and folders. Each entry stores its content and metadata (name, date, compression method). When reading a ZIP, the library parses the central directory and local file headers per the PKZIP specification, inflating compressed entries on demand. When generating, it serializes the entry tree into a valid ZIP byte stream, compressing entries with the pako DEFLATE library. All operations return promises, allowing non-blocking processing of large archives.
Setup & Configuration
- Install via npm or load from a CDN for browser use
- Create a new archive with
new JSZip()and add files with.file(name, content) - Read an existing ZIP with
JSZip.loadAsync(data)where data is a Blob, ArrayBuffer, or base64 string - Set compression options in
generateAsync():{ compression: 'DEFLATE', compressionOptions: { level: 6 } } - Access individual files with
zip.file('path/to/file').async('string')for lazy extraction
Key Features
- Pure JavaScript with no native dependencies or WebAssembly
- Reads and writes ZIP64 archives for files larger than 4 GB
- Streaming generation via
generateInternalStream()for memory-efficient output - Compatible with password-protected ZIP reading via community extensions
- Works identically in browser, Node.js, and Deno environments
Comparison with Similar Tools
- Archiver (Node.js) — streaming ZIP creation for servers; JSZip also works in the browser
- fflate — faster compression via WebAssembly; JSZip has a simpler API and wider adoption
- pako — raw DEFLATE compression only; JSZip provides the full ZIP container format on top
- StreamSaver.js — handles downloading large files; pair with JSZip to stream ZIP downloads in the browser
FAQ
Q: Can JSZip handle large archives in the browser?
A: Yes. Use generateInternalStream() for streaming output and loadAsync() for lazy parsing. Very large archives may still be constrained by browser memory limits.
Q: Does JSZip support password-protected ZIP files? A: The core library does not encrypt or decrypt. Community forks and plugins add password support using the traditional ZIP encryption scheme.
Q: Can I add binary files like images to a ZIP?
A: Yes. Pass the content as a Blob, ArrayBuffer, or Uint8Array to zip.file() and set { binary: true } if needed.
Q: How does JSZip compare to the native Compression Streams API? A: The Compression Streams API provides raw DEFLATE/gzip compression. JSZip adds the ZIP container format, file metadata, and folder structure on top of compression.