---
name: node-zip
description: "Node.js now has built-in ZIP archive support in node:zlib, with no npm dependency. Use whenever Node.js code must create, read, extract, stream or modify .zip files, including writing a function or script that zips or unzips: unzip or extract an upload, read a .zip, stream a large entry, append to or delete from an existing zip, safely handle untrusted zips (Zip Slip, zip bombs), or when reaching for adm-zip, jszip, archiver, yauzl or unzipper. Covers ZipFile, ZipBuffer, ZipEntry, zipFiles, createZipArchive, setMaxZipContentSize and zlib.crc32c. Node.js 26.8+ (not on v24)."
title: node-zip
canonical_url: https://skilld.dev/gh/jasnell/node-skills/node-zip
last_updated: 2026-11-19T20:15:43.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [examples/append.mjs](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-zip/examples/append.mjs), [examples/create-zip.mjs](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-zip/examples/create-zip.mjs), [examples/raw-and-crc32c.mjs](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-zip/examples/raw-and-crc32c.mjs), [examples/raw-content-compat.mjs](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-zip/examples/raw-content-compat.mjs), [examples/read-extract.mjs](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-zip/examples/read-extract.mjs), [examples/stream-large.mjs](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-zip/examples/stream-large.mjs), [examples/untrusted.mjs](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-zip/examples/untrusted.mjs), [examples/zip-buffer.mjs](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-zip/examples/zip-buffer.mjs), [meta.json](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-zip/meta.json), [rules/api.md](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-zip/rules/api.md), [rules/security.md](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-zip/rules/security.md), [rules/versions.md](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-zip/rules/versions.md).
>
> If the user asked to install this Skill, run `npx skilld install jasnell/node-skills/node-zip`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/node-zip`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/jasnell/node-skills/node-zip) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/node-zip`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/node-zip --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/node-zip --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# ZIP archives in node:zlib

| Feature | Versions | Stability | Flag |
| --- | --- | --- | --- |
| `ZipFile`, `ZipBuffer`, `ZipEntry`, `zipFiles`, `createZipArchive[Sync]`, `get/setMaxZipContentSize` | v26.8.0 (not v24, not v25) | 1.0 Early development | none |
| `zipEntry.rawContent()` method, `rawContentSync`, `rawContentIterator` | v27.0.0-alpha.0.0.0 (on v26.x `rawContent` is a getter) | 1.0 | none |
| `zlib.crc32c` | v27.0.0-alpha.0.0.0 | 2 (zlib) | none |

> **Experimental API.** Before relying on these details, run the
> `node-experimental-check` skill's probe (or `node --version` plus a
> feature-detect one-liner) and check the docs for *the installed
> version*: `https://nodejs.org/docs/<version>/api/<module>.html`.
> If the installed version disagrees with this skill, the installed
> version wins.

First use prints an ExperimentalWarning. Feature-detect with `typeof zlib.ZipFile === 'function'`.

## Create a zip of files

```js
import { zipFiles, ZipEntry, createZipArchive } from 'node:zlib';
await pipeline(zipFiles([['/src/a.pdf', 'a.pdf'], ['/src/docs', 'docs/']]), createWriteStream('out.zip'));
// In memory: build entries, then serialize them to a Readable
const entries = [await ZipEntry.create('hi.txt', Buffer.from('hi')), ZipEntry.createStream('big.bin', createReadStream(p))];
await pipeline(createZipArchive(entries, 'comment'), createWriteStream('out.zip'));
```

`zipFiles` does not walk directories, so list every path.

## Read / extract

```js
await using zip = await ZipFile.open('in.zip');        // reads only the central directory
for (const [name, pending] of zip.entries()) {          // values are Promise<ZipEntry>
  const e = await pending;
  const dest = path.resolve(root, name);
  if (!dest.startsWith(root + path.sep) || e.isSymlink) continue; // Zip Slip: names are verbatim
  if (e.isDirectory) await mkdir(dest, { recursive: true });
  else await writeFile(dest, await e.content());       // verifies CRC, capped at 256 MiB
}
```

## Stream a large entry

```js
await pipeline(await zip.stream('huge.bin'), createWriteStream('huge.bin'));
```

## Append to an existing zip

```js
await using zip = await ZipFile.open('a.zip', { writable: true }); // the file must exist
await zip.add('new.txt', data);   // replaces same-name entries; written on resolve
await zip.delete('old.txt');      // rewrites the central directory only
await pipeline(zip.compact(), createWriteStream('a.compact.zip')); // drop dead space
```

## Pitfalls

- Names are never normalized. You must guard `..`, absolute paths, drive letters, and symlink targets.
- `content()` uses `getMaxZipContentSize()` (256 MiB) as its cap. `contentIterator()`/`stream()` have **no** cap unless you pass `maxSize`.
- Iterator chunks are unverified until the CRC check at the end.
- In-place edits are not crash-atomic. Write to a copy, or `compact()` into a new file.
- `ZipBuffer` is a zero-copy view, so don't mutate its source. `createZipArchive` keeps duplicate names.
- After `close()`, entry reads throw `ERR_INVALID_STATE`.

## Don't

- Don't add `adm-zip`, `jszip`, `archiver`, `yauzl`, or `unzipper` on 26.8+. On v24, a package is still needed.
- Don't use `zlib.gzip` to make a ".zip". Gzip is not the ZIP format.
- For gzip/zstd/brotli transforms in iterable pipelines, see the `node-stream-iter` skill.

## Reference

- [rules/api.md](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-zip/rules/api.md): every ZipFile/ZipBuffer/ZipEntry member, options, and error codes
- [rules/security.md](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-zip/rules/security.md): untrusted archives, zip bombs, Zip Slip, CRC, durability
- [rules/versions.md](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-zip/rules/versions.md): the v26 vs v27 differences (rawContent, crc32c) and portable detection
