Skip to content

Commit c7a3f01

Browse files
committed
zlib: add ZIP archive read/write support
Adds ZipEntry, ZipFile, and ZipBuffer to node:zlib for reading, creating, and mutating ZIP archives, reusing the existing deflate/zstd bindings rather than adding new native code. ZipEntry reads and builds individual archive members (store, deflate, and zstd compression), with a streaming variant for producing content incrementally and synchronous counterparts for every method, documented as event-loop-blocking (mirroring node:fs). ZipBuffer is an in-memory, always-writable view over an archive buffer: entries can be added, replaced, or deleted, and toBuffer()/toBufferSync() serialize the current live set into a fresh archive. ZipFile is a disk-backed archive, read-only by default and writable when opened with { writable: true }. Writes append new entries where the central directory used to be and rewrite the central directory in place; deletions rewrite the central directory only, without growing the file. compact()/compactSync() stream a fresh archive with no dead entries left behind. An internal busy-flag counter prevents synchronous methods from running while an asynchronous mutation hasn't settled yet, since both would otherwise compute the same central-directory offset. Also adds six ERR_ZIP_* error codes and getMaxZipContentSize()/ setMaxZipContentSize() to bound decompressed entry size by default.
1 parent f91697a commit c7a3f01

15 files changed

Lines changed: 4742 additions & 0 deletions

doc/api/errors.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3674,6 +3674,50 @@ All attempts at serializing an uncaught exception from a worker thread failed.
36743674

36753675
The requested functionality is not supported in worker threads.
36763676

3677+
<a id="ERR_ZIP_ENTRY_CORRUPT"></a>
3678+
3679+
### `ERR_ZIP_ENTRY_CORRUPT`
3680+
3681+
A ZIP archive entry failed CRC-32 verification, or produced more or fewer
3682+
bytes than its declared uncompressed size, while being read.
3683+
3684+
<a id="ERR_ZIP_ENTRY_NOT_FOUND"></a>
3685+
3686+
### `ERR_ZIP_ENTRY_NOT_FOUND`
3687+
3688+
A named entry was requested from a [`ZipFile`][] or [`ZipBuffer`][] that does
3689+
not contain an entry with that name.
3690+
3691+
<a id="ERR_ZIP_ENTRY_TOO_LARGE"></a>
3692+
3693+
### `ERR_ZIP_ENTRY_TOO_LARGE`
3694+
3695+
A ZIP archive entry's declared size exceeds the configured limit, or a
3696+
provided entry name or comment exceeds the 65,535-byte encoded length that
3697+
the ZIP format allows.
3698+
3699+
<a id="ERR_ZIP_INVALID_ARCHIVE"></a>
3700+
3701+
### `ERR_ZIP_INVALID_ARCHIVE`
3702+
3703+
Data that was expected to be a ZIP archive, or a structure within one, is
3704+
missing, out of bounds, or otherwise inconsistent with the ZIP format.
3705+
3706+
<a id="ERR_ZIP_NOT_WRITABLE"></a>
3707+
3708+
### `ERR_ZIP_NOT_WRITABLE`
3709+
3710+
A mutating method (such as `zipFile.addEntry()` or `zipFile.delete()`) was
3711+
called on a [`ZipFile`][] that was not opened with `{ writable: true }`.
3712+
3713+
<a id="ERR_ZIP_UNSUPPORTED_FEATURE"></a>
3714+
3715+
### `ERR_ZIP_UNSUPPORTED_FEATURE`
3716+
3717+
A ZIP archive uses a feature outside of what this implementation supports,
3718+
such as entry encryption, an unsupported compression method, or a multi-disk
3719+
archive.
3720+
36773721
<a id="ERR_ZLIB_INITIALIZATION_FAILED"></a>
36783722

36793723
### `ERR_ZLIB_INITIALIZATION_FAILED`
@@ -4674,6 +4718,8 @@ An error occurred trying to allocate memory. This should never happen.
46744718
[`util.inspect()`]: util.md#utilinspectobject-options
46754719
[`util.parseArgs()`]: util.md#utilparseargsconfig
46764720
[`v8.startupSnapshot.setDeserializeMainFunction()`]: v8.md#v8startupsnapshotsetdeserializemainfunctioncallback-data
4721+
[`ZipBuffer`]: zlib.md#class-zlibzipbuffer
4722+
[`ZipFile`]: zlib.md#class-zlibzipfile
46774723
[`zlib`]: zlib.md
46784724
[crypto digest algorithm]: crypto.md#cryptogethashes
46794725
[debugger]: debugger.md

0 commit comments

Comments
 (0)