Skip to content

Commit 5ba72ae

Browse files
authored
zlib: add ZipEntry, ZipFile, and ZipBuffer
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> PR-URL: #64339 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Aviv Keller <me@aviv.sh>
1 parent 53ea5a1 commit 5ba72ae

36 files changed

Lines changed: 9679 additions & 0 deletions

doc/api/errors.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3669,6 +3669,58 @@ All attempts at serializing an uncaught exception from a worker thread failed.
36693669

36703670
The requested functionality is not supported in worker threads.
36713671

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

36743726
### `ERR_ZLIB_INITIALIZATION_FAILED`
@@ -4612,6 +4664,8 @@ An error occurred trying to allocate memory. This should never happen.
46124664
[`ServerResponse`]: http.md#class-httpserverresponse
46134665
[`Temporal`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal
46144666
[`Writable`]: stream.md#class-streamwritable
4667+
[`ZipBuffer`]: zlib.md#class-zlibzipbuffer
4668+
[`ZipFile`]: zlib.md#class-zlibzipfile
46154669
[`child_process`]: child_process.md
46164670
[`cipher.getAuthTag()`]: crypto.md#ciphergetauthtag
46174671
[`crypto.getDiffieHellman()`]: crypto.md#cryptogetdiffiehellmangroupname

0 commit comments

Comments
 (0)