moonbit-community/flate/zip does not have a README file

    ZipError

    pub suberror ZipError {
    ZipError(ZipErrorKind, String)
    }

    Structured ZIP failure: a stable category plus a human-readable diagnostic.

    Archive

    pub struct Archive {
    // private fields
    }

    An in-memory ZIP archive: an ordered list of entries plus an archive comment. Reading a ZIP materializes this; writing serializes it back.

    Archive::Archive

    fn Archive::Archive() -> Archive

    Create an empty archive.

    Archive::add

    fn Archive::add(self : Archive, name : String, data : BytesView, compression? : Compression, data_descriptor? : Bool) -> Unit

    Append a new entry whose payload is data. data is owned by the archive, so later Bytes mutation cannot corrupt it. The default method is Deflate; pass Store to keep the payload verbatim. Setting data_descriptor=true emits the entry in streaming form (zeroed local sizes + a trailing data descriptor).

    Archive::clone

    fn Archive::clone(self : Archive) -> Archive

    Returns an independently mutable snapshot of this archive. The clone shares entry payloads and preserved source records (immutable Bytes) but owns a fresh entries array, so add/replace/remove on either side never affects the other. add and replace defensively own their inputs.

    Archive::comment

    fn Archive::comment(self : Archive) -> BytesView

    The archive-level comment bytes (empty when none).

    Archive::entries

    fn Archive::entries(self : Archive) -> ArrayView[Entry]

    The archive's entry list in order.

    Archive::fork

    #deprecated("use `Archive::clone` instead")
    fn Archive::fork(self : Archive) -> Archive

    Deprecated alias of Archive::clone.

    Archive::get

    fn Archive::get(self : Archive, name : StringView) -> BytesView?

    A read-only view of an entry payload, or None when absent.

    Archive::remove

    fn Archive::remove(self : Archive, name : StringView) -> Bool

    Remove the entry named name. Returns false when no such entry exists.

    Archive::replace

    fn Archive::replace(self : Archive, name : StringView, data : BytesView) -> Bool

    Replace the payload of the entry named name. The entry keeps its method policy but drops its raw source records (the next write re-encodes it). Its original position in the archive is retained, so a byte-preserving write keeps the entry where it was. Returns false when no such entry exists.

    Archive::retained_size_estimate

    fn Archive::retained_size_estimate(self : Archive) -> Int64

    Conservatively estimates bytes retained by this materialized archive: the archive comment, captured trailer records, and per-entry payloads, names, and preserved source records (each with a bookkeeping reserve). Payloads and records are counted exactly; only allocator/container overhead uses a fixed per-entry reserve. The source package buffer an archive was read from is not included.

    Archive::set_comment

    fn Archive::set_comment(self : Archive, comment : BytesView) -> Unit

    Replace the archive-level comment. Long comments (over 65535 bytes) are rejected at write time. Changing the comment invalidates a retained end-record template, so a later byte-preserving write regenerates the trailer with the new comment.

    Compression

    pub(all) enum Compression {
    Store
    Deflate
    } derive(Eq,
    Debug
    )

    The ZIP compression methods this package can read and write.

    Compression::equal

    fn Compression::equal(Compression, Compression) -> Bool

    Compression::not_equal

    fn Compression::not_equal(x : Compression, y : Compression) -> Bool

    Entry

    pub struct Entry {
    // private fields
    }

    A single archive entry: its decoded payload plus the metadata the central directory carried for it. Entries produced by read also retain their raw source records (raw_local_record / raw_central_record) for byte-preserving rewrites; entries built with Archive::add do not.

    Entry::compression

    fn Entry::compression(self : Entry) -> Compression

    Entry::crc32

    fn Entry::crc32(self : Entry) -> UInt

    The entry's stored CRC-32: the central-directory value for entries read from an archive, or computed at add time for entries created in memory.

    Entry::data

    fn Entry::data(self : Entry) -> BytesView

    Entry::data_descriptor

    fn Entry::data_descriptor(self : Entry) -> Bool

    Entry::name

    fn Entry::name(self : Entry) -> String

    Entry::raw_central_record

    fn Entry::raw_central_record(self : Entry) -> BytesView?

    The original central directory record bytes of a pristine entry read from an archive, or None for entries created in memory or replaced after a read.

    Entry::raw_local_record

    fn Entry::raw_local_record(self : Entry) -> BytesView?

    The original local header + payload (+ data descriptor) bytes of a pristine entry read from an archive, or None for entries created in memory or replaced after a read.

    LimitKind

    pub(all) enum LimitKind {
    PackageBytes
    Entries
    EntryUncompressedBytes
    TotalUncompressedBytes
    PreservedSourceBytes
    OutputBytes
    } derive(Eq,
    Debug
    )

    Which bounded resource was exceeded during a bounded read or write. The payload-related kinds guard against decompression bombs; PreservedSource bounds the raw local/central records retained for byte-preserving rewrites; OutputBytes bounds a serialization's total size.

    LimitKind::equal

    fn LimitKind::equal(LimitKind, LimitKind) -> Bool

    LimitKind::not_equal

    fn LimitKind::not_equal(x : LimitKind, y : LimitKind) -> Bool

    ReadLimits

    pub struct ReadLimits {
    max_package_bytes : Int
    max_entries : Int
    max_entry_uncompressed_bytes : Int
    max_total_uncompressed_bytes : Int
    max_preserved_source_bytes : Int
    }

    Resource bounds applied to a bounded read. Every field is a ceiling in bytes (or, for max_entries, a count); ReadLimits::default() imposes no limits. max_preserved_source_bytes bounds the raw local/central records retained in memory so a byte-preserving rewrite cannot be weaponized as an unbounded retention bomb.

    ReadLimits::default

    fn ReadLimits::default() -> ReadLimits

    The default, unlimited resource bounds.

    ReadLimits::with_entries_limit

    fn ReadLimits::with_entries_limit(self : ReadLimits, limit : Int) -> ReadLimits

    A copy of self with a new entry-count ceiling.

    ReadLimits::with_entry_limit

    fn ReadLimits::with_entry_limit(self : ReadLimits, limit : Int) -> ReadLimits

    A copy of self with a new per-entry uncompressed ceiling.

    ReadLimits::with_package_limit

    fn ReadLimits::with_package_limit(self : ReadLimits, limit : Int) -> ReadLimits

    A copy of self with a new package-size ceiling.

    ReadLimits::with_preserved_source_limit

    fn ReadLimits::with_preserved_source_limit(self : ReadLimits, limit : Int) -> ReadLimits

    A copy of self with a new preserved-source-record ceiling.

    ReadLimits::with_total_limit

    fn ReadLimits::with_total_limit(self : ReadLimits, limit : Int) -> ReadLimits

    A copy of self with a new total uncompressed ceiling.

    ZipErrorKind

    pub(all) enum ZipErrorKind {
    Truncated
    InvalidSignature
    MissingEndOfCentral
    UnsupportedCompression(Int)
    InvalidUtf8
    UnsupportedFeature
    LimitExceeded(LimitKind, Int, Int)
    Cancelled
    } derive(Eq,
    Debug
    )

    Machine-readable category for a ZIP container failure. The accompanying ZipError message is intended for diagnostics rather than branching.

    ZipErrorKind::equal

    ZipErrorKind::not_equal

    fn ZipErrorKind::not_equal(x : ZipErrorKind, y : ZipErrorKind) -> Bool

    CENTRAL_HEADER_SIG

    let CENTRAL_HEADER_SIG : UInt

    DATA_DESCRIPTOR_SIG

    let DATA_DESCRIPTOR_SIG : UInt

    END_OF_CENTRAL_SIG

    let END_OF_CENTRAL_SIG : UInt

    FLAG_DATA_DESCRIPTOR

    let FLAG_DATA_DESCRIPTOR : Int

    FLAG_DEFLATE_STRENGTH

    let FLAG_DEFLATE_STRENGTH : Int

    FLAG_ENCRYPTED

    let FLAG_ENCRYPTED : Int

    FLAG_UTF8

    let FLAG_UTF8 : Int

    LOCAL_HEADER_SIG

    let LOCAL_HEADER_SIG : UInt

    MAX_U32

    let MAX_U32 : UInt

    ZIP64_EOCD_SIG

    let ZIP64_EOCD_SIG : UInt

    ZIP64_EXTRA_ID

    let ZIP64_EXTRA_ID : Int

    ZIP64_LOCATOR_SIG

    let ZIP64_LOCATOR_SIG : UInt

    read

    fn read(bytes : BytesView, limits? : ReadLimits, cancelled? : () -> Bool) -> Archive raise ZipError

    Read a ZIP archive from bytes, decoding every entry. limits bounds the package size, entry count, per-entry and total decompressed bytes, and the source records retained for byte-preserving rewrites; cancelled is polled across parsing and decoding. Each entry exposes the central directory's stored CRC-32 via Entry::crc32; it is not verified during this read — callers that need integrity checking compare it against @checksum.crc32(entry.data()). Failures carry a stable ZipErrorKind plus a diagnostic.

    write

    fn write(archive : Archive, level? : Int) -> Bytes raise ZipError

    Serialize archive into a ZIP byte stream, encoding every entry fresh (DEFLATE by default, STORED when the entry says so). level 0-9 trades speed for ratio on the DEFLATE payloads.

    write_limited

    fn write_limited(archive : Archive, max_output_bytes~ : Int, level? : Int) -> Bytes raise ZipError

    Serialize archive like write while enforcing a hard output ceiling. The output is sized first, so an over-limit archive raises LimitExceeded(OutputBytes, ...) without materializing a candidate buffer.

    write_preserving

    fn write_preserving(archive : Archive, level? : Int) -> Bytes raise ZipError

    Serialize archive, re-emitting pristine entries (those read from a previous archive and never replaced) byte-for-byte from their retained source records, so unchanged packages round-trip without loss. Entries created or replaced in memory are encoded fresh.

    write_preserving_limited

    fn write_preserving_limited(archive : Archive, max_output_bytes~ : Int, level? : Int) -> Bytes raise ZipError

    Serialize archive like write_preserving while enforcing a hard output ceiling (sized first, so an over-limit archive raises without materializing a candidate buffer).