npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

sum-zipper

v3.0.4

Published

Create ZIP files in the browser with zero dependencies

Readme

// ============================================ // README.md // ============================================ /*

Browser ZIP

A lightweight, zero-dependency library for creating ZIP files in the browser using the native Compression Streams API.

Installation

Via npm

npm install sum-zipper

Via CDN (No build step required!)

<script src="https://unpkg.com/sum-zipper@latest/dist/browser-zip.min.js"></script>
<script>
  const { createZip, downloadZip } = BrowserZip;
  // Ready to use!
</script>

Download

Download browser-zip.min.js from the releases page and include it in your HTML.

Usage

Basic Example with Folder Structure

import { createZip, downloadZip } from "browser-zip";

const files = [
  { name: "folder1/hello.txt", content: "Hello World!" },
  {
    name: "folder1/subfolder/data.json",
    content: JSON.stringify({ foo: "bar" }),
  },
  { name: "folder2/readme.md", content: "# My Project" },
  { name: "root-file.txt", content: "This is in the root" },
];

const zipData = await createZip(files);
downloadZip(zipData, "my-archive.zip");

From File Input (Preserves Folder Structure)

<!-- Allow directory selection -->
<input type="file" webkitdirectory multiple />
import { createZipFromFiles, downloadZip } from "browser-zip";

const input = document.querySelector('input[type="file"]');
input.addEventListener("change", async (e) => {
  const files = Array.from(e.target.files);
  // Automatically preserves folder structure from webkitRelativePath
  const zipData = await createZipFromFiles(files);
  downloadZip(zipData, "uploaded-folder.zip");
});

Create Nested ZIPs (Zip each child folder separately)

import { createNestedZip, downloadZip } from "browser-zip";

// Your folder structure:
const files = [
  { name: "parent/src/index.js", content: 'console.log("main")' },
  { name: "parent/src/utils.js", content: "export const help = () => {}" },
  { name: "parent/dist/package/index.ts", content: "export {}" },
  { name: "parent/dist/build.js", content: "compiled code" },
  { name: "parent/README.md", content: "# Parent level file" },
];

// This creates: parent.zip with src.zip, dist.zip, and README.md inside
const zipData = await createNestedZip(files);
downloadZip(zipData, "parent.zip");

Result when extracted:

parent.zip/
├── src.zip          ← Contains index.js, utils.js
├── dist.zip         ← Contains package/index.ts, build.js
└── README.md        ← Root files stay as-is

What's inside src.zip:

src/
├── index.js
└── utils.js

What's inside dist.zip:

dist/
├── package/
│   └── index.ts
└── build.js

Create from Object

import { createZipFromObject, downloadZip } from "browser-zip";

const fileObject = {
  "docs/readme.md": "# Documentation",
  "src/index.js": 'console.log("hello")',
  "config.json": JSON.stringify({ version: "1.0.0" }),
};

const zipData = await createZipFromObject(fileObject);
downloadZip(zipData, "project.zip");

Get as Blob (for uploading)

import { createZipBlob } from "browser-zip";

const files = [{ name: "file.txt", content: "Hello!" }];

const blob = await createZipBlob(files);

// Upload to server
const formData = new FormData();
formData.append("file", blob, "archive.zip");
await fetch("/upload", { method: "POST", body: formData });

API

createZip(files: ZipFile[]): Promise<Uint8Array>

Creates a ZIP archive from an array of files.

Parameters:

  • files: Array of objects with name (string) and content (string | Uint8Array)

Returns: Promise that resolves to a Uint8Array containing the ZIP data

downloadZip(zipData: Uint8Array, filename?: string): void

Triggers a download of the ZIP file in the browser.

Parameters:

  • zipData: The ZIP data as Uint8Array
  • filename: Optional filename (default: 'archive.zip')

createZipFromFiles(fileList: File[]): Promise<Uint8Array>

Helper function to create a ZIP from browser File objects.

Parameters:

  • fileList: Array of File objects (e.g., from file input)

Returns: Promise that resolves to a Uint8Array containing the ZIP data

createZipBlob(files: ZipFile[]): Promise<Blob>

Creates a ZIP and returns it as a Blob (useful for uploads).

Parameters:

  • files: Array of ZipFile objects

Returns: Promise that resolves to a Blob

createNestedZip(files: ZipFile[], parentFolderName?: string): Promise<Uint8Array>

Creates a ZIP where each direct child folder becomes its own nested ZIP file.

Parameters:

  • files: Array of ZipFile objects with paths
  • parentFolderName: Optional parent folder name

Returns: Promise that resolves to a Uint8Array

Example:

// Input files:
// parent/src/file.js
// parent/dist/build.js

const zipData = await createNestedZip(files);
// Creates: parent.zip containing src.zip and dist.zip

createNestedZipWithParent(parentFolderName: string, files: ZipFile[]): Promise<Uint8Array>

Same as createNestedZip but ensures all files are under a parent folder first.

Parameters:

  • parentFolderName: Name of the parent folder
  • files: Array of ZipFile objects

Returns: Promise that resolves to a Uint8Array

Browser Compatibility

This library uses the Compression Streams API, which is supported in:

  • Chrome 80+
  • Edge 80+
  • Safari 16.4+
  • Firefox 113+

Features

✅ Zero dependencies
✅ Full TypeScript support
✅ Preserves folder structure
✅ Handles binary and text files
✅ Works with File API
✅ Create Blobs for uploads
✅ Lightweight and fast

License

MIT *