Skip to content

zlib: add ZIP archive support to zlib (ZipFile,ZipBuffer,ZipEntry) - #64339

Open
pipobscure wants to merge 1 commit into
nodejs:mainfrom
pipobscure:ziparchives
Open

zlib: add ZIP archive support to zlib (ZipFile,ZipBuffer,ZipEntry)#64339
pipobscure wants to merge 1 commit into
nodejs:mainfrom
pipobscure:ziparchives

Conversation

@pipobscure

@pipobscure pipobscure commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Add ZIP archive support to the node:zlib module through three classes
and a set of helpers:

  • ZipEntry: a single archive member, with buffered reads (content()),
    bounded-memory streaming reads (contentIterator()), and
    create()/createStream() for building members.
  • ZipFile: random access to an archive backed by a file descriptor,
    reading members lazily without retaining their content and writing
    new members in place; opened with open()/openSync().
  • ZipBuffer: a zero-copy, in-memory view over an archive already held
    in a Buffer.

createZipArchive() serializes a sequence of entries into an archive
byte stream, and setMaxZipContentSize() bounds the default in-memory
decompression size. Every operation has both an asynchronous and a
synchronous form.

P.S.: my CLA should be on file and I wrote this myself so COO is declared

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Jul 7, 2026
@pipobscure pipobscure changed the title zlib, vfs: add ZIP archive read/write support and an archive vfs provider zlib, vfs: add ZIP archive support and an archive vfs provider Jul 7, 2026
@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.48790% with 60 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.27%. Comparing base (6572cf5) to head (4fdc3fe).
⚠️ Report is 73 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/zip/file.js 97.12% 20 Missing ⚠️
lib/internal/zip/entry.js 98.50% 12 Missing and 2 partials ⚠️
lib/internal/zip/headers.js 97.17% 14 Missing ⚠️
lib/internal/zip/fs-util.js 94.00% 4 Missing and 5 partials ⚠️
lib/internal/zip/compression.js 99.33% 2 Missing ⚠️
lib/internal/zip/archive.js 99.65% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #64339      +/-   ##
==========================================
+ Coverage   90.13%   90.27%   +0.14%     
==========================================
  Files         741      755      +14     
  Lines      242251   246219    +3968     
  Branches    45615    46413     +798     
==========================================
+ Hits       218355   222278    +3923     
- Misses      15396    15424      +28     
- Partials     8500     8517      +17     
Files with missing lines Coverage Δ
lib/internal/errors.js 97.91% <100.00%> (+<0.01%) ⬆️
lib/internal/zip.js 100.00% <100.00%> (ø)
lib/internal/zip/binary.js 100.00% <100.00%> (ø)
lib/internal/zip/buffer.js 100.00% <100.00%> (ø)
lib/internal/zip/constants.js 100.00% <100.00%> (ø)
lib/internal/zip/content-size.js 100.00% <100.00%> (ø)
lib/internal/zip/dos.js 100.00% <100.00%> (ø)
lib/internal/zip/extra-fields.js 100.00% <100.00%> (ø)
lib/internal/zip/header-builders.js 100.00% <100.00%> (ø)
lib/zlib.js 98.13% <100.00%> (+0.06%) ⬆️
... and 6 more

... and 30 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pipobscure

This comment was marked as outdated.

@pipobscure
pipobscure force-pushed the ziparchives branch 3 times, most recently from 0f2b879 to 4258e94 Compare July 7, 2026 19:20
pipobscure added a commit to pipobscure/node that referenced this pull request Jul 7, 2026
Codecov flagged low patch coverage on lib/internal/zip.js and
lib/internal/vfs/providers/archive.js in nodejs#64339. Add tests exercising
Zip64 extra-field parsing, DOS date/time edge cases, streaming-entry
state guards, decodeMemberStream/decodeMemberSync's duplicated error
branches, the ZipBuffer/ZipFile iteration protocols, several on-disk
ZipFile error paths, and ArchiveFileHandle's direct read/write/stat/
truncate surface plus a handful of provider-level error branches the
existing tests didn't reach.
@pipobscure
pipobscure force-pushed the ziparchives branch 2 times, most recently from 2a56a15 to 27ab6b4 Compare July 7, 2026 21:54
@bakkot

bakkot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

See also #45651

Comment thread doc/api/vfs.md Outdated
@pipobscure

pipobscure commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

See also #45651

Thanks @bakkot !!!

I think the time has come for it on the one hand, and on the other I added some „motivation“ links earlier. Here some more detail:

Based on this, we can modify the loader to directly load from an archive. If we do that, we get application bundles. pipobscure#5 & pipobscure#6

Which can then in turn be used to easily create application bundles: https://github.com/pipobscure/experimental-sea

So the world had changed enough that it‘s worth proposing again.

@JakobJingleheimer
JakobJingleheimer self-requested a review July 8, 2026 08:40
@pipobscure
pipobscure force-pushed the ziparchives branch 2 times, most recently from f157686 to 233f865 Compare July 8, 2026 11:29
@mcollina

mcollina commented Jul 8, 2026

Copy link
Copy Markdown
Member

I like this a lot. It's likely better to split this into 2 PRs, one for Zip support and one for VFS-Zip, so the Zip support could theoretically be backportable on its own.

Comment thread doc/api/zlib.md
@pipobscure

This comment was marked as outdated.

@pipobscure

pipobscure commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

As per @mcollina I split this into two PRs.

I have the vfs-provider ready to go as follow up one (as it depends on this being merged)

I also made sure that the streaming side of things was actually as clean as I intended, and added a few more tests.

@pipobscure pipobscure changed the title zlib, vfs: add ZIP archive support and an archive vfs provider zlib, vfs: add ZIP archive support to zlib Jul 8, 2026
Comment thread test/parallel/test-zlib-zip-vfs.js Outdated
@pipobscure pipobscure changed the title zlib, vfs: add ZIP archive support to zlib zlib: add ZIP archive support to zlib (ZipFile,ZipBuffer,ZipEntry) Jul 8, 2026
@bakkot

bakkot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Might be worth borrowing some tests from other projects: e.g. python, go, info-zip. There's a lot of edge cases with zip files. (Python's tests are larger than this whole PR put together.)

Not all directly applicable because this doesn't include the ability to extract to disk, fortunately.

@trivikr trivikr added the zlib Issues and PRs related to the zlib subsystem. label Jul 9, 2026
@pipobscure

Copy link
Copy Markdown
Contributor Author

Might be worth borrowing some tests from other projects

I've added a bunch more tests and compared to what go/python/info-zip do. (info-zip is cli exercise, so it's not entirely clear what gets tested).

I also gave zip.js an once over and concluded that it was too large a file (it originated from separate files that I've had for ages combined into one).

So I split it back out so it would be easier to review. And gave that another look.

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina added the request-ci Add this label to start a Jenkins CI on a PR. label Jul 10, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 10, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/74727/

@mcollina

Copy link
Copy Markdown
Member

@jasnell @JakobJingleheimer ptal

@trivikr trivikr mentioned this pull request Jul 16, 2026
@GeoffreyBooth

Copy link
Copy Markdown
Member

My 2022 self thanks you for doing this 😀

@JakobJingleheimer

Copy link
Copy Markdown
Member

Awesome!

I'm on holiday til next weekend. I'll take a look when I'm back 🙂 I tagged myself to review so I don't forget.

@trivikr
trivikr requested a review from jasnell July 21, 2026 05:40
Add ZIP archive support to the node:zlib module through three classes
and a set of helpers:

- ZipEntry: a single archive member, with buffered reads (content()),
  bounded-memory streaming reads (contentIterator()), and
  create()/createStream() for building members.
- ZipFile: random access to an archive backed by a file descriptor,
  reading members lazily without retaining their content and writing
  new members in place; opened with open()/openSync().
- ZipBuffer: a zero-copy, in-memory view over an archive already held
  in a Buffer.

createZipArchive() serializes a sequence of entries into an archive
byte stream, and setMaxZipContentSize() bounds the default in-memory
decompression size. Every operation has both an asynchronous and a
synchronous form.

Signed-off-by: Philipp Dunkel <pip@pipobscure.com>
@pipobscure

Copy link
Copy Markdown
Contributor Author

Rebased on latest main to resolve the conflict

@pipobscure

Copy link
Copy Markdown
Contributor Author

The failing mac tests seem to be entirely unrelated

Failed tests:
out/Release/node /Users/runner/work/node/node/node/test/parallel/test-debugger-extract-function-name.mjs
out/Release/node --test-reporter=./test/common/test-error-reporter.js --test-reporter-destination=stdout /Users/runner/work/node/node/node/test/parallel/test-repl-user-error-handler.js

can someone verify my deduction please.

@mcollina mcollina added the request-ci Add this label to start a Jenkins CI on a PR. label Jul 24, 2026
@pipobscure

This comment was marked as outdated.

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina added request-ci Add this label to start a Jenkins CI on a PR. and removed request-ci Add this label to start a Jenkins CI on a PR. labels Jul 29, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 29, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@pipobscure

This comment was marked as outdated.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@mcollina

mcollina commented Jul 30, 2026

Copy link
Copy Markdown
Member

Everything is green, CI is ok, we are missing another @nodejs/tsc approval as this a large PR.

Comment thread doc/api/zlib.md
added: REPLACEME
-->

> Stability: 1 - Experimental

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use the newer experimental stages like 1.0, 1.1 etc...

@marco-ippolito marco-ippolito left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@targos targos left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am reviewing. You can dismiss my request for changes if I don't answer by tomorrow.

@panva panva added the experimental Issues and PRs related to experimental features. label Jul 30, 2026

@panva panva left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import { createGzip } from 'node:zlib'

This stable import emits ZIP experimental warning because of how our ESM facade evaluates the getters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

experimental Issues and PRs related to experimental features. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. semver-minor PRs that contain new features and should be released in the next minor version. zlib Issues and PRs related to the zlib subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.