List entries in the opened archive. Directories have names ending with '/'.
@eryx/compression/zip Module
JSON
Summary
Classes
Functions
API Reference
Classes
ZipReader
Properties
ZipReader:Read
Read a named entry from the opened archive. Returns nil if not found.
Parameters
entry filename (case-sensitive)
Returns
the entry contents or nil
ZipReader:Close
Close the reader and release any pinned buffer. Safe to call multiple times.
Functions
zip.open
Fast magic-byte check. Returns true if the buffer looks like a zip archive.
Checks for PK\x03\x04 (normal zip) or PK\x05\x06 (empty zip).
Open a zip archive from an in-memory buffer and return a ZipReader.
The returned reader pins the provided buffer to avoid copying; call
reader:close() (or let it be GC'd) to release the buffer.
Parameters
zip archive bytes
Returns
reader object
zip.isZip
Quick check whether data begins with ZIP magic bytes.
Parameters
data to inspect
Returns
true when buffer looks like a zip archive
zip.list
List all entries in a zip archive without extracting.
Directories appear as entries whose name ends with '/'.
Return a list of EntryInfo for every entry in the given archive.
This is a convenience wrapper that opens the archive transiently.
Parameters
zip archive bytes
Returns
ordered list of entries
zip.unpack
Extract all files from a zip into a name->buffer table. Directory entries are skipped. Unpack all non-directory entries into a name -> buffer table.
Parameters
zip archive bytes
Returns
map of filename -> contents
zip.read
Read a single named entry from a zip. Returns nil if not found. Name is matched case-sensitively. This opens the archive, locates the entry, reads it, and closes the archive.
Parameters
zip archive bytes
entry filename to read (case-sensitive)
Returns
entry contents or nil if not found
zip.pack
Pack a name->buffer table into a zip archive returned as a buffer. options.method: "deflate" (default) or "store" (no compression) options.level: 1 (fastest) - 9 (best), -1 = default Create a ZIP archive from a map of filename -> buffer. @param options? PackOptions -- optional packing options
Parameters
map of filenames to data
Returns
the generated zip archive
Types
EntryInfo
Zip file entry metadata returned by zip.list and ZipReader:list.
@field name string: the entry filename (directories end with '/')
@field size number: uncompressed size in bytes
@field compressedSize number: compressed size in bytes
@field method number: compression method (compare with zip.METHOD_*)
@field crc32 number: CRC32 checksum of the entry
PackOptions
Constants
- Compression method constants (for comparing EntryInfo.method)
zip.METHOD_STORE=0zip.METHOD_DEFLATE=8