Skip to content

zlib: add tar archive support - #67975

Open
mcollina wants to merge 2 commits into
nodejs:mainfrom
mcollina:zlib-tar
Open

mcollina wants to merge 2 commits into
nodejs:mainfrom
mcollina:zlib-tar

Conversation

@mcollina

@mcollina mcollina commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Adds experimental tar support to node:zlib, next to the ZIP API: reading (listTar(), extractTar(), createTarExtractStream(), tarEntries(), TarParser) and writing (TarEntry.create*(), createTarArchive(), tarFiles()), with sync variants.

tar is the basis of npm: every package is a tarball, so every install unpacks them and every publish creates one. Having it in core benefits the whole ecosystem.

The API is compatible with the one of node-tar: the extraction options (cwd, strip, filter, preservePaths, preserveOwner, onwarn, ...) and the entry fields and type names are the same.


AI generated, reviewed by me

Add an experimental tar reader to node:zlib, ported from fast-tar:
listTar(), extractTar(), createTarExtractStream(), tarEntries(), their
synchronous variants, and the TarParser they are built on.

Signed-off-by: Matteo Collina <hello@matteocollina.com>
Add TarEntry.create(), createStream(), createSymlink() and createLink(),
and createTarArchive(), createTarArchiveSync() and tarFiles() to write
them, mirroring the ZIP creation API.

Signed-off-by: Matteo Collina <hello@matteocollina.com>
@nodejs-github-bot nodejs-github-bot added errors Issues and PRs related to JavaScript errors originating in Node.js core. needs-ci PRs that need a full CI run. zlib Issues and PRs related to the zlib module and its compression dependencies. labels Dec 2, 2026
@MikeMcC399

This comment was marked as resolved.

@mcollina

mcollina commented Dec 2, 2026

Copy link
Copy Markdown
Member Author

Not public, and it does not need to be, sorry for the mistake.

@mcollina
mcollina requested a review from pipobscure December 2, 2026 19:23
@mcollina
mcollina marked this pull request as ready for review December 2, 2026 19:23
@mcollina

mcollina commented Dec 2, 2026

Copy link
Copy Markdown
Member Author

@nodejs/tsc this is a big PR and it needs your approval.

@codecov

codecov Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.71914% with 318 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.64%. Comparing base (40c40fa) to head (1871641).
⚠️ Report is 85 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/tar/unpack.js 85.59% 128 Missing and 7 partials ⚠️
lib/internal/tar/source.js 89.27% 69 Missing and 5 partials ⚠️
lib/internal/tar/unpack-sync.js 88.40% 37 Missing ⚠️
lib/internal/tar/entries.js 92.30% 23 Missing and 1 partial ⚠️
lib/internal/tar/header.js 97.10% 10 Missing ⚠️
lib/internal/tar/archive.js 98.51% 5 Missing and 3 partials ⚠️
lib/internal/tar/unpack-common.js 96.87% 8 Missing ⚠️
lib/internal/tar/parser.js 98.70% 6 Missing ⚠️
lib/internal/tar/pax.js 97.16% 4 Missing ⚠️
lib/internal/tar/entry.js 98.57% 2 Missing and 1 partial ⚠️
... and 4 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67975      +/-   ##
==========================================
+ Coverage   90.53%   90.64%   +0.11%     
==========================================
  Files         805      817      +12     
  Lines      285915   291978    +6063     
  Branches    55213    56746    +1533     
==========================================
+ Hits       258841   264655    +5814     
- Misses      17186    17390     +204     
- Partials     9888     9933      +45     
Files with missing lines Coverage Δ
lib/internal/errors.js 98.42% <100.00%> (+0.29%) ⬆️
lib/internal/tar.js 100.00% <100.00%> (ø)
lib/zlib.js 98.49% <100.00%> (+0.07%) ⬆️
lib/internal/tar/api.js 99.68% <99.68%> (ø)
lib/internal/tar/decompress.js 99.00% <99.00%> (ø)
lib/internal/tar/entry.js 98.57% <98.57%> (ø)
lib/internal/tar/paths.js 98.05% <98.05%> (ø)
lib/internal/tar/pool.js 95.65% <95.65%> (ø)
lib/internal/tar/pax.js 97.16% <97.16%> (ø)
lib/internal/tar/parser.js 98.70% <98.70%> (ø)
... and 7 more

... and 92 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.

@aduh95 aduh95 added the large-pr PRs subject to the large-PR policy. label Dec 2, 2026
@bakkot

bakkot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Have you read https://astral.sh/blog/tar-codec? It's a good overview of some of the pitfalls with tar parsing, and they have tests you could borrow.

There's also this other large test suite. It recommends a policy of rejecting ambiguities in tar files that could make implementations extract different files, which I'd love to see node follow.

(Alternatively, you could compile tar-codec to wasm and use that, instead of writing and maintaining your own. That approach has much to recommend it.)

Edit: also I note that you added support for extracting to disk, which the zip support deliberately omitted. Nothing inherently wrong with that but a little odd for them to be asymmetric, and there's many more pitfalls when extracting rather than merely reading.

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

Labels

errors Issues and PRs related to JavaScript errors originating in Node.js core. large-pr PRs subject to the large-PR policy. needs-ci PRs that need a full CI run. zlib Issues and PRs related to the zlib module and its compression dependencies.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants