Client-side Streaming ZIP Generator

2.5.0 · active · verified Tue Apr 21

client-zip is a lightweight, dependency-free JavaScript library for client-side generation of streaming ZIP archives directly in the browser. It allows developers to concatenate multiple files, often fetched from HTTP requests, into a single downloadable ZIP file without server-side processing. The current stable version is 2.5.0, with regular patch and minor releases indicating active maintenance. Key differentiators include its small bundle size (2.6kB gzipped), superior performance compared to alternatives like JSZip (reportedly 40x faster), and native support for modern browser streaming APIs. It handles Zip64 archives, necessary for large files, though this means generated ZIPs require a reader compatible with "ZIP version 4.5" and may not be universally readable by all older ZIP utilities. It does not perform file compression or unzipping.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to use `downloadZip` to create a ZIP file from multiple inputs (a string and a fetched resource) and initiate a client-side download.

import { downloadZip } from 'client-zip';

async function downloadTestZip() {
  // Define what we want in the ZIP
  const code = await fetch("https://raw.githubusercontent.com/Touffy/client-zip/master/src/index.ts");
  const intro = { name: "intro.txt", lastModified: new Date(), input: "Hello. This is the client-zip library." };

  // Get the ZIP stream in a Blob
  const blob = await downloadZip([intro, code]).blob();

  // Make and click a temporary link to download the Blob
  const link = document.createElement("a");
  link.href = URL.createObjectURL(blob);
  link.download = "test.zip";
  link.click();
  link.remove();

  // In real life, don't forget to revoke your Blob URLs if you use them to prevent memory leaks.
  URL.revokeObjectURL(link.href);
}

downloadTestZip();

view raw JSON →