@eryx/compression/zip Module

JSON

Summary

Classes

ZipReader:Read(name: string)buffer?

Functions

zip.open(data: buffer)ZipReader
zip.isZip(data: buffer)boolean
zip.list(data: buffer){ EntryInfo }
zip.unpack(data: buffer){ [string]: buffer }
zip.read(data: buffer, name: string)buffer?
zip.pack(files: { [string]: buffer }, options: PackOptions?)buffer

API Reference

Classes

ZipReader

Properties

ZipReader:List

List entries in the opened archive. Directories have names ending with '/'.

ZipReader:List(){ EntryInfo }

Returns

list of entries in archive

ZipReader:Read

Read a named entry from the opened archive. Returns nil if not found.

ZipReader:Read(name: string)buffer?

Parameters

name: string

entry filename (case-sensitive)

Returns

buffer?

the entry contents or nil

ZipReader:Close

Close the reader and release any pinned buffer. Safe to call multiple times.

ZipReader:Close()()

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.

zip.open(data: buffer)ZipReader

Parameters

data: buffer

zip archive bytes

Returns

reader object

zip.isZip

Quick check whether data begins with ZIP magic bytes.

zip.isZip(data: buffer)boolean

Parameters

data: buffer

data to inspect

Returns

boolean

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.

zip.list(data: buffer){ EntryInfo }

Parameters

data: buffer

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.

zip.unpack(data: buffer){ [string]: buffer }

Parameters

data: buffer

zip archive bytes

Returns

{ [string]: buffer }

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.

zip.read(data: buffer, name: string)buffer?

Parameters

data: buffer

zip archive bytes

name: string

entry filename to read (case-sensitive)

Returns

buffer?

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

zip.pack(files: { [string]: buffer }, options: PackOptions?)buffer

Parameters

files: { [string]: buffer }

map of filenames to data

Returns

buffer

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

name: string
size: number
compressedSize: number
method: number
crc32: number

PackOptions

method: ("store" | "deflate")?
level: number?

Constants