Creates the instance
The Reader instance used to read data.
Optionaloptions: ZipReaderConstructorOptions
The options.
Reading a zip file requires random access because the central directory located at the end of the
file is read first. A ReadableStream instance, or an object providing only a readable property
(e.g. a file handle), is therefore buffered entirely in memory when the instance is initialized. To
read a large seekable resource without buffering it, pass a custom Reader implementation
that reads the requested byte ranges directly, or a lazily-read Blob instance when the runtime
provides one, e.g. await fs.openAsBlob(path) on Node.js or Bun.file(path) on Bun. See
Reader for an example reading a Deno.FsFile with random access.
OptionalappendedThe data appended after the zip file.
The global comment of the zip file.
Unlike EntryMetaData#comment, it is exposed as raw bytes because the zip format defines no way to record its encoding: section 4.4.26 of the zip specification says nothing about it, and the end of central directory record has neither a general purpose bit flag nor an extra field, so the language encoding flag (see Appendix D - Language Encoding (EFS)) cannot apply to it. Decode it with the encoding agreed with the producer of the zip file.
OptionaldigitalThe data of the digital signature record of the central directory (see ZipWriterCloseOptions#signCentralDirectory), if the zip file contains one.
zip.js does not verify signatures. The signed data is the central directory records, read at ZipReader#directoryOffset, and it never includes the digital signature record itself. Some writers (e.g. SecureZIP) store that record inside ZipReader#directoryLength, so verifying the whole declared range would always fail.
OptionaldirectoryThe length in bytes of the central directory as declared in the end of central directory record. Some
writers (e.g. SecureZIP) include the digital signature record in that length, so subtract
6 + digitalSignature.length from it when the record is stored inside the declared range.
OptionaldirectoryThe offset of the central directory in the zip file.
OptionalprependedThe data prepended before the zip file.
OptionalwarningsThe non-fatal diagnostics deposited while reading the entries, replaced every time ZipReader#getEntries or ZipReader#getEntriesGenerator runs.
A warning reports a characteristic of the zip file observed in data the parse had already read: depositing one never costs additional I/O, and a well-formed zip file deposits none. Each ArchiveWarning#reason value is deposited at most once per call, with ArchiveWarning#filename naming the first entry it applies to when it applies to an entry.
Two kinds of reasons are deposited. Observations are always non-fatal: WARNING_UNSORTED_CENTRAL_DIRECTORY,
WARNING_UNKNOWN_VERSION (the low byte of the "version needed to extract" field exceeds the highest
known zip specification version; the high byte is ignored because some writers store a host identifier in it),
WARNING_COMPRESSED_PATCHED_DATA (bit 5 of the general purpose bit flag),
WARNING_MALFORMED_EXTRA_FIELD, WARNING_UNKNOWN_ZIP64_EXTENSIBLE_DATA,
WARNING_WRAPPED_ENTRIES_COUNT and WARNING_PREPENDED_CENTRAL_DIRECTORY (the prepended data
holds a central directory of its own, i.e. another archive precedes this one and other readers may report
its entries instead). The other reasons are the checks that
strictness: "strict" rejects with ERR_AMBIGUOUS_ARCHIVE: when the effective strictness tolerates
one of them and the evidence is already in hand, the same reason string is deposited as a warning instead —
WARNING_APPENDED_DATA, WARNING_PREPENDED_DATA, WARNING_TRAILING_CENTRAL_DIRECTORY_DATA,
WARNING_DUPLICATE_FILENAME and WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY.
WARNING_MULTIPLE_END_OF_CENTRAL_DIRECTORY is the one reason of that group which is never tolerated,
so it is only ever the reason of an error.
The warnings related to the local file header of an entry are deposited on EntryMetaData#warnings when its data is read, not here.
Calls ZipReader#close, making the instance usable with await using
Closes the zip file
It cancels the ReadableStream instance passed to the constructor when nothing has been read
from it, which is the only resource a ZipReader instance can hold. It does nothing otherwise: the
stream is already consumed once ZipReader#getEntries has read the entries into memory, and the
Reader instances are never closed, they belong to the caller. The entries returned by
ZipReader#getEntries can therefore still be read after calling it.
Returns all the entries in the zip file
Optionaloptions: ZipReaderGetEntriesOptions
The options.
A promise resolving to an array of Entry instances.
Returns a generator used to iterate on all the entries in the zip file
Optionaloptions: ZipReaderGetEntriesOptions
The options.
An asynchronous generator of Entry instances.
Represents an instance used to read a zip file.
Example
Here is an example showing how to read the text data of the first entry from a zip file: