constructor
zlib.ZipBuffer.constructor
Not implemented in Bun
Parses the archive's central directory. Throws an ERR_ZIP_INVALID_ARCHIVE or ERR_ZIP_UNSUPPORTED_FEATURE error if buffer is not a well-formed, supported archive.
buffer is not copied: the ZipBuffer retains a zero-copy view of it (for a TypedArray, DataView, or ArrayBuffer, of the underlying ArrayBuffer) and reads entry content directly from it on demand. Do not mutate or reuse that memory while the ZipBuffer or any entry read from it is still live; pass a copy if it might change.
A complete ZIP archive.
Referenced types
class ZipBuffer
An in-memory, zero-copy view over the entries of a ZIP archive already held in a Buffer, TypedArray, DataView, or ArrayBuffer. Its set of entries can be edited - entries added or removed - but, unlike ZipFile, those edits are not written into the source buffer: a newly added entry is held as a separate in-memory ZipEntry (the passed buffer is a fixed-size view with no room to append to), and removal just drops the entry from ZipBuffer's index. The original bytes are never modified. zipBuffer.toBuffer() serializes the current set of entries into a fresh archive.
ZipBuffer does not copy the archive you hand it. It keeps a view onto that memory and reads each entry's content lazily and directly from it, which is what makes construction cheap regardless of archive size. The trade-off is that you must not modify or reuse that memory - including the ArrayBuffer backing a TypedArray/DataView - while the ZipBuffer, or any ZipEntry obtained from it, is still in use: a later read would observe the change and may fail or return corrupt data. Pass a copy (for example Buffer.from(source)) if the source might be mutated or reused.
add() and toBuffer() each have a *Sync counterpart (addSync(), toBufferSync()) that performs the same compression work synchronously. As with the synchronous node:fs APIs, these block the Node.js event loop and further JavaScript execution until the operation completes; use them only where synchronous execution is appropriate (for example, short-lived scripts or startup code), not in code that must stay responsive.
- readonly comment: string
The archive-level comment, preserved byte-for-byte across
zipBuffer.toBuffer()calls unless overridden. The bytes are decoded as UTF-8 when they are valid UTF-8 and as CP437 otherwise (the field carries no encoding flag of its own). - add(filename: string,
Equivalent to
zipBuffer.addEntry(await zlib.ZipEntry.create(filename, data, options)).@param filenameThe entry's name within the archive. A trailing
/marks a directory entry.@param dataThe entry's complete, uncompressed content.
@param optionsSee
zlib.ZipEntry.create().@returnsPromisefulfilled with the createdZipEntry. - filename: string,
The synchronous version of
zipBuffer.add(). Equivalent tozipBuffer.addEntry(zlib.ZipEntry.createSync(filename, data, options)).@param filenameThe entry's name within the archive. A trailing
/marks a directory entry.@param dataThe entry's complete, uncompressed content.
@param optionsSee
zlib.ZipEntry.createSync().@returnsThe created entry.
Removes every entry.
- @returns
trueif an entry namednameexisted and was removed. - @returns
Iteratorof entry names. - ): Promise<NonSharedBuffer>;
Serializes the current set of entries - in the order they were added or read - into a fresh archive, switching to Zip64 structures automatically as needed (see
zlib.createZipArchive()).@param optionsAn archive comment, as a shorthand for
{ comment: options }. The comment defaults tozipBuffer.comment.@returnsPromisefulfilled with aBuffercontaining the serialized archive. - ): NonSharedBuffer;
The synchronous version of
zipBuffer.toBuffer()(seezlib.createZipArchiveSync()).@param optionsSee
zipBuffer.toBuffer().@returnsThe serialized archive.