moonbitlang/core/compress/zlib does not have a README file

    DeflateAction

    Requested action for one streaming compression step.

    The action applies after the complete input view has been consumed. If a step reports partial consumption, re-present the remaining suffix with the same action.

    Status

    Outcome of one step of the streaming DEFLATE state machine.

    The engine is runtime-agnostic: it moves bytes between an input view and an output buffer and suspends by returning one of these, so any driver — a synchronous loop or an async adapter — can resume it.

    StepResult

    Result of one streaming codec call. The counts describe the input prefix accepted and the output prefix written by this call, including when it returns Done. Keep the result to inspect it independently of later calls.

    Strategy

    Whole-buffer compression strategy. Levels are clamped to 0-9; level 0 emits stored blocks only.

    ZlibError

    pub suberror ZlibError {
    ZlibError(ZlibErrorKind, String)
    }

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

    Decoder

    type Decoder

    Streaming zlib decompressor

    Decoder::Decoder

    fn Decoder::Decoder(dictionary? : BytesView) -> Decoder

    Create a fresh zlib decompressor. Supply dictionary when the stream was compressed with a preset dictionary : the header's DICTID is verified against it before use.

    Decoder::check_end

    Declare EOF after all input is accepted; NeedMoreOutput requires draining with step.

    Decoder::is_finished

    fn Decoder::is_finished(self : Decoder) -> Bool

    Whether the whole zlib stream has been decoded and its trailer verified.

    Decoder::step

    fn Decoder::step(self : Decoder, input : BytesView, output : MutArrayView[Byte]) ->
    StepResult
    raise ZlibError

    Run one decompression step. Buffers a bounded prefix of input, then decodes plaintext into output. Returns StepResult with this call's status, consumed and produced byte counts; drop only input[:result.consumed]. Pending body input is drained before accepting more; output backpressure may leave a suffix unaccepted. Input is borrowed only during this call, and any retained suffix is copied. Once all source input has been accepted, call check_end to declare EOF. Drain any pending output through step with empty input; EOF stays latched. Incomplete headers, bodies and trailers then raise ZlibError instead of requesting more input. If the final accepted view also contains bytes after the zlib trailer, retrieve that read-ahead with unused_input(). On failure, the decoder locks the first ZlibError kind/message and rethrows it on every later call. A failing call returns no result; its output buffer may already contain partial output.

    Decoder::unused_input

    fn Decoder::unused_input(self : Decoder) -> Bytes

    Bytes accepted by step beyond the end of the completed zlib stream.

    A buffered sync reader or async transport commonly delivers the zlib trailer and bytes from the next protocol frame in one read. After Done, this method returns the accepted read-ahead suffix. Any unaccepted suffix remains with the caller, as reported by result.consumed. It is empty before completion and when no suffix was buffered.

    Encoder

    type Encoder

    Streaming zlib compressor (RFC 1950). Feed input and drain compressed output with step, finalize with action=Finish; binds no I/O trait.

    Encoder::Encoder

    fn Encoder::Encoder(level? : Int, dictionary? : BytesView, fast_store? : Bool) -> Encoder

    Create a fresh zlib compressor. level 0-9 (clamped) trades speed for ratio; 0 = stored only, 6 = default. A preset dictionary (RFC 1950 FDICT) preloads the match window and is announced in the header via its Adler-32; the decoder must supply the same dictionary. Opt-in fast_store samples each block; it may increase output size. The default is false.

    Encoder::is_finished

    fn Encoder::is_finished(self : Encoder) -> Bool

    Whether the complete zlib stream has been emitted.

    Encoder::reset

    fn Encoder::reset(self : Encoder, dictionary? : BytesView) -> Unit

    Reset to the start of a fresh zlib stream, keeping the compression level and fast_store policy and reusing the compressor's allocations. The next stream's output is identical to that of a newly constructed Encoder with the same options. A preset dictionary applies to the new stream only, exactly as for the constructor.

    Encoder::step

    Run one compression step. Accepts a bounded prefix of input, folds only that prefix into Adler-32, then drains zlib output into output. Returns StepResult with this call's status, consumed and produced byte counts. Drop only input[:result.consumed]: a large view may be partially consumed under output backpressure. Re-present its suffix with the same action; once the complete view is accepted, SyncFlush or Finish remains sticky. Later input is left unconsumed while the finished stream is drained.

    ZlibErrorKind

    pub(all) enum ZlibErrorKind {
    Truncated
    InvalidHeader
    DictionaryRequired
    DictionaryMismatch
    InvalidDeflate
    ChecksumMismatch
    TrailingData
    OutputLimitExceeded(limit~ : UInt64, observed~ : UInt64)
    Cancelled
    InvalidArgument
    } derive(Eq,
    Debug
    )

    Machine-readable category for a zlib decoding failure. The accompanying ZlibError message remains intended for diagnostics rather than branching. Output limits, cancellation and invalid limits apply to decompress only.

    ZlibErrorKind::equal

    compress

    fn compress(input : BytesView, strategy? :
    Strategy
    , dictionary? : BytesView, fast_store? : Bool) -> Bytes

    Compress a complete zlib stream with the selected DEFLATE strategy. dictionary seeds the history; its full Adler-32 is stored as DICTID. fast_store may bypass the strategy for sampled inputs, trading ratio for speed.

    decompress

    fn decompress(input : BytesView, dictionary? : BytesView, max_output? : Int, cancelled? : () -> Bool) -> Bytes raise ZlibError

    Decode zlib data and verify its Adler-32 trailer. max_output caps decoded bytes (default: Bytes capacity); exceeding it raises OutputLimitExceeded, a negative value InvalidArgument. Supply dictionary for an FDICT stream. cancelled is polled at entry, every 4 KiB decoded or checksummed; true raises Cancelled.