October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

How to Create, Read, and Download ZIP Files with JSZip

Use JSZip's Promise-based API to create archives, read entries, and deliver browser downloads or Node.js files.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

JSZip lets JavaScript applications create, load, and edit ZIP archives in memory. Use generateAsync() to create an archive, loadAsync() to open one, and entry.async() to read a file from it. In a browser, generate a Blob and use FileSaver.js to download it; in Node.js, generate a Buffer and write it with the filesystem API.

How JSZip represents an archive

The JSZip project describes its library as “a javascript library for creating, reading and editing .zip files, with a lovely and simple API.” The project page lists version 3.10.2: JSZip project.

As an Amazon Associate I earn from qualifying purchases.

A JSZip instance holds archive entries in memory. Create one with new JSZip(); use file(name, data) to add a file. Add a directory with folder(name), or use slash-separated paths such as images/note.txt. The file data documentation also covers supported inputs, including browser Blob and File objects.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How to create and download a ZIP in a browser

Install JSZip and FileSaver.js in your project, then generate a Blob and hand it to FileSaver.js. FileSaver is a separate helper; it is not part of JSZip.

#1 Best Overall
Express Zip File Compression Software - Zip and Compress Files & Folders Easily [Download]
  • Fast and efficient file zipping and unzipping
  • Compress files for email transmission
  • Archive data using less disk space
  • Small download; install and open or compress archives in seconds
  • Open and extract many archive formats including rar, cab, tar, 7z, iso and more
import JSZip from "jszip";
import { saveAs } from "file-saver";

const zip = new JSZip();
zip.file("hello.txt", "Hello worldn");
zip.folder("images").file("note.txt", "Files can be grouped in folders.");

const blob = await zip.generateAsync({ type: "blob" });
saveAs(blob, "example.zip");

The await is important: generateAsync() returns a Promise that resolves to the requested archive representation. The documented browser flow is Blob generation followed by saveAs(blob, "filename.zip"). See the JSZip write guide and generation options.

Choose a suitable output type

  • For a browser download, use type: "blob".
  • In Node.js, use type: "nodebuffer" and write the Buffer with Node’s filesystem API.
  • For another API, choose a supported byte-array representation that matches what it expects. Browser support for output types can vary; check JSZip.support.

The JSZip guide also documents a data-URL download approach, but notes its length and filename limitations. For a modern browser download, the Blob-and-FileSaver route is the documented choice.

Rank #2
WinZip 30 Pro | File Management, Encryption, Compression & Backup Software [PC Download]
  • One-stop file manager: Seamless integration with leading cloud storage providers, zip/unzip all major compression formats, and keep your computer clean with automated background tools + 6 exclusive Pro apps to boost your productivity
  • WinZip SafeShare: Confidently share your files to many locations after compressing and securing with military-grade encryption and time bomb capabilities
  • WinZip Duplicate File Finder: A deduplication utility that makes detecting and deleting duplicate files a quick and effortless process
  • WinZip PDF Express: Create, convert, and edit PDF documents. Reorder, add, or delete pages, and easily combine multiple documents into a single PDF. Add a custom watermark, or reply to and delete comments
  • WinZip Image Manager: Easily convert image formats, rotate, resize, and crop for single or multiple images, then share your pictures by encrypting and removing camera information or EXIF data

How to read a ZIP and extract a file

Pass the archive data to loadAsync(), then call async(outputType) on the entry you want. Both steps are asynchronous, so await their Promises or chain them.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const zip = await JSZip.loadAsync(fileOrArrayBuffer);
const entry = zip.file("hello.txt");

if (!entry) {
  throw new Error("hello.txt is not in the archive");
}

const text = await entry.async("string");

loadAsync() resolves to the loaded archive. Looking up a missing path with zip.file(name) returns no file object, so check for the entry before calling async(). Choose the output type for the extracted data according to how the application will use it. See the archive loading documentation and JSZip FAQ and examples.

Rank #3
Express Zip Professional [PC Online code]
  • Quickly create and extract zip files
  • Open zip, rar, 7z, cab, tar, and other popular data achieve formats
  • Compress files for archiving, email, or saving disk space
  • Easily drag and drop files and folders
  • Add encryptions to archives or files while you zip

Load files selected in a browser

JSZip accepts browser File inputs. A file input’s selected files can be passed to loadAsync() to open an archive, or added directly as entries when creating a new archive. The read guide shows the archive-loading workflow; the file data documentation covers adding file inputs.

How to generate a ZIP in Node.js

For a Buffer suitable for Node.js APIs, request nodebuffer, then write it using the filesystem module.

Rank #4
WinZip 30 | File Management, Encryption & Compression Software [PC Download]
  • Save time and space: With efficient file compression and duplicate file detection, you can store, open, zip, and encrypt; keep your computer organized and simplify time-consuming tasks
  • Protect your data: Password-protect important files and secure them with easy-to-use encryption capabilities like military-grade AES 256-bit encryption
  • Easy file sharing: Shrink files to create smaller, safer email attachments, then share directly from WinZip to social media, email, IM or popular cloud storage providers
  • Open any format: Compatible with all major formats to open, view, zip, or share. Compression formats include Zip, Zipx, RAR, 7z, TAR, GZIP, VHD, XZ, POSIX TAR and more
  • Manage your files in one place: Access, organize, and manage your files on your computer, network, or cloud service
import JSZip from "jszip";
import { writeFile } from "node:fs/promises";

const zip = new JSZip();
zip.file("hello.txt", "Hello worldn");

const buffer = await zip.generateAsync({ type: "nodebuffer" });
await writeFile("example.zip", buffer);

For streamed output to a file, JSZip’s Node.js guide demonstrates generateNodeStream() piped into a writable file stream. See the write guide.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Compression, memory, and compatibility choices

Generation supports STORE (no compression) and DEFLATE. Set compressionOptions: { level: 1..9 } to choose a DEFLATE level. Changing the generation level does not recompress entries that are already compressed to a different level. Consult the generation options for the option details.

Best Value
Zip It (Jewel Case)
  • Compresses documents and files
  • Saves space on your hard drive
  • Easily send large files via e-mail
  • Intuitive user interface
  • Easy to learn and use

By default, streamFiles is false: JSZip holds processed file data in memory during generation. Setting streamFiles: true can reduce memory use by using ZIP data descriptors, but some ZIP readers may not support those descriptors. This is a compatibility trade-off, not a guarantee that JSZip can handle arbitrarily large archives efficiently. Test the intended archive sizes and target readers before relying on streamed generation. The advanced usage guide describes the streaming behavior.

Handle imported ZIP paths safely

Starting with JSZip 3.8.0, imported filenames containing .. path components are sanitized to mitigate ZIP Slip. The original path remains available as unsafeOriginalName; use the sanitized entry name for subsequent processing and do not assume an archive’s supplied paths are safe. This library behavior is a protective measure, not a general security guarantee for every operation your application performs. See the loadAsync documentation.

Use the Promise-based API in current JSZip

JSZip 3 moved generation, archive loading, and entry reads to Promise-based methods: generateAsync(), loadAsync(), and async(). Examples using older synchronous APIs need updating to await or chain these methods. Consult the upgrade guide when adapting legacy code.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Quick Recap

Bestseller No. 1
Express Zip File Compression Software - Zip and Compress Files & Folders Easily [Download]
Express Zip File Compression Software - Zip and Compress Files & Folders Easily [Download]
Fast and efficient file zipping and unzipping; Compress files for email transmission; Archive data using less disk space
$29.99
Bestseller No. 3
Express Zip Professional [PC Online code]
Express Zip Professional [PC Online code]
Quickly create and extract zip files; Open zip, rar, 7z, cab, tar, and other popular data achieve formats
$29.99
Bestseller No. 5
Zip It (Jewel Case)
Zip It (Jewel Case)
Compresses documents and files; Saves space on your hard drive; Easily send large files via e-mail
$3.99

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.