Skip to content

zlib: add raw content read methods to ZipEntry - #66801

Open
pipobscure wants to merge 1 commit into
nodejs:mainfrom
pipobscure:zlib-zip-raw-content
Open

pipobscure wants to merge 1 commit into
nodejs:mainfrom
pipobscure:zlib-zip-raw-content

Conversation

@pipobscure

Copy link
Copy Markdown
Contributor

zipEntry.rawContent was a getter that exposed the retained buffer of an in-memory entry and returned null for a file-backed or streaming one, so the still-compressed bytes of a member read through ZipFile could not be obtained at all.

Replace it with rawContent(), rawContentSync() and rawContentIterator(), which mirror content(), contentSync() and contentIterator() but return the bytes as stored, without decompressing or verifying them. They work for every entry that has readable content, return caller-owned buffers from the buffered variants, and accept a maxSize bound on the compressed size.

The motivation for this change is that I found a great use-case for this: web serving directly from an archive. If Accept-Encoding: gzip or Accept-Encoding: deflate is presented and the archive already has the part compressed that way, then it can serve that staright without any overhead.

So I decided to make change rawContent from a getter to a function and have the rawContent family of functions match what the content functions do. But since that changesbthe experimental API, it's probably a semver-minor.

@mcollina can you advise if changing the API from getter to function is ok in an experimental thing?

zipEntry.rawContent was a getter that exposed the retained buffer of an
in-memory entry and returned null for a file-backed or streaming one,
so the still-compressed bytes of a member read through ZipFile could
not be obtained at all.

Replace it with rawContent(), rawContentSync() and
rawContentIterator(), which mirror content(), contentSync() and
contentIterator() but return the bytes as stored, without
decompressing or verifying them. They work for every entry that has
readable content, return caller-owned buffers from the buffered
variants, and accept a maxSize bound on the compressed size.

Signed-off-by: Philipp Dunkel <pip@pipobscure.com>
@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Oct 16, 2026
@codecov

codecov Bot commented Oct 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.49%. Comparing base (f513ec7) to head (8f4a4f9).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #66801   +/-   ##
=======================================
  Coverage   90.49%   90.49%           
=======================================
  Files         797      797           
  Lines      277686   277738   +52     
  Branches    53362    53370    +8     
=======================================
+ Hits       251292   251348   +56     
+ Misses      16796    16790    -6     
- Partials     9598     9600    +2     
Files with missing lines Coverage Δ
lib/internal/zip/entry.js 98.60% <100.00%> (+0.46%) ⬆️

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

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

Labels

needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants