packkit/zip
ZIP archive encoder and decoder.
This module implements the PKZIP local-file-header / central directory layout for the “stored” (uncompressed) and “deflate” methods, plus the Zip64 extensions (APPNOTE.TXT §4.4) needed to carry archives with > 65535 entries, central-directory regions
4 GiB, individual entries > 4 GiB, or local-header offsets 4 GiB. ZIP is modelled as an archive family, not a recipe: per-entry compression is selected through
Methodvalues rather than throughpackkit/recipe.
On the decoder side: when the standard EOCD record has any
sentinel field (0xFFFF for the 16-bit slots, 0xFFFFFFFF for
the 32-bit slots), the decoder follows the Zip64 EOCD locator at
eocd_offset - 20 to the Zip64 EOCD record and reads the real
64-bit values from there. Per-entry Zip64 extra fields
(header_id = 0x0001) are parsed in both the central-directory
entry and the local file header so that compressed / uncompressed
sizes and local-header offsets above the 4 GiB boundary decode
correctly.
On the encoder side: each entry transparently switches to the
Zip64 extra field when any of its uncompressed_size,
compressed_size, or local_header_offset would not fit in 32
bits. Archives whose total entry count or central-directory
region overflow the legacy 16-/32-bit EOCD slots also emit a
Zip64 EOCD record + locator so the resulting bytes round-trip
through any conforming Zip64 reader.
Types
Values
pub fn decode(
bytes bytes: BitArray,
) -> Result(archive.Archive, error.ArchiveError)
Decode a ZIP archive using default limits.
pub fn decode_with_limits(
bytes bytes: BitArray,
limits limits: limit.Limits,
) -> Result(archive.Archive, error.ArchiveError)
Decode a ZIP archive using explicit limits.
pub fn decode_with_password(
bytes bytes: BitArray,
password password: String,
) -> Result(archive.Archive, error.ArchiveError)
Decode a ZIP archive whose entries may be protected by the
PKWARE traditional (“ZipCrypto”) encryption scheme. The
password is applied to every encrypted entry; entries without
the gp-flag encryption bit decode unchanged. Wrong-password
detection relies on the 12-byte encryption header check byte
(the high byte of the entry’s CRC-32), so a wrong password
surfaces as ArchiveInvalid.
pub fn decode_with_password_and_limits(
bytes bytes: BitArray,
password password: String,
limits limits: limit.Limits,
) -> Result(archive.Archive, error.ArchiveError)
Same as decode_with_password but with explicit limits.
pub fn deflate(level level: level.Level) -> Method
Deflate-compressed ZIP member method.
pub fn encode(
archive archive_value: archive.Archive,
) -> Result(BitArray, error.ArchiveError)
Encode a logical archive into a ZIP byte stream using the stored (uncompressed) method for every entry.
pub fn encode_with_method(
archive archive_value: archive.Archive,
method method: Method,
) -> Result(BitArray, error.ArchiveError)
Encode a logical archive into a ZIP byte stream using a chosen
per-entry method. Supports store, deflate, bzip2, zstd,
and xz.
pub fn inner_codec(method: Method) -> option.Option(codec.Codec)
Optional inner codec corresponding to the method.
pub fn lzma() -> Method
PKWARE LZMA ZIP member method (PKZIP method 14). Wraps a raw
LZMA1 range-coded stream in the 4-byte SDK preamble + 5-byte
property block (lc=3 / lp=0 / pb=2, dict size 64 KiB). The
encoder emits the stream with general-purpose flag bit 1 set so
the decoder relies on the central-directory uncompressed size
instead of an in-stream EOS marker.