Library guide · API index and notation
This page is generated from the bundled library in this checkout. Signatures and adjacent source comments are reproduced below; the linked guide explains usage, storage, failures, and platform support.
import "std/compress/deflate"
Names used in signatures
Unqualified names denote this package’s types (including other source files in the same package), language built-ins, or generic parameters such as T. Qualified names use the import aliases below. These aliases belong to the library source; import a dependency yourself to use its alias in your program.
| Alias | Package | Source file |
|---|---|---|
slice |
core/slice |
encode.dodo, encoder.dodo |
decode
Function · Source
Decodes one complete raw DEFLATE stream into output and stops after its final block. Expansion is limited by output.len; on error the output contents are unspecified.
pub fn decode(input: &[u8], output: &mut[u8]) -> DecodeResult!Error
decode_with_window
Function · Source
Like decode, but rejects distances beyond window, which must be 1 through WINDOW_SIZE. zlib uses this for windows its header declares smaller.
pub fn decode_with_window(input: &[u8], output: &mut[u8], window: usize) -> DecodeResult!Error
Decoder
Struct · Source
Incremental raw DEFLATE decoder with its own 32 KiB history, so output may be delivered in buffers of any size. It never reads past the stream’s last byte, leaving any trailer or following data to the caller.
pub struct Decoder {
// Private implementation fields omitted.
}
Decoder.new
Function · Source
pub fn new() -> Decoder
Decoder.new_with_window
Function · Source
Rejects distances beyond window, which must be 1 through WINDOW_SIZE.
pub fn new_with_window(window: usize) -> Decoder!Error
Decoder.reset
Function · Source
Returns the decoder to its initial state, keeping its window limit.
pub fn reset(&mut self)
Decoder.is_done
Function · Source
pub fn is_done(&self) -> bool
Decoder.process
Function · Source
Decodes as much as input and output allow. Either may be empty. Counts cover this call only. Errors are final: later calls repeat InvalidData.
pub fn process(&mut self, input: &[u8], output: &mut[u8]) -> Progress!Error
Error
Enum · Source
Raw RFC 1951 DEFLATE. The zlib and gzip packages share these result types, so one Decoder or Encoder interface covers all three framings.
pub enum Error {
// The input ended inside a stream. Incremental decoders report NeedInput.
Truncated,
InvalidData,
// The caller's output buffer cannot hold the result.
OutputFull,
// A zlib or gzip check value or size disagrees with the decoded data.
ChecksumMismatch,
// A zlib stream requires a preset dictionary.
UnsupportedDictionary,
// A compression level outside 0 through 9, storage shorter than
// ENCODER_BUFFER_LEN or WORKSPACE_LEN, or an invalid gzip header field.
InvalidArgument
}
Status
Enum · Source
pub enum Status {
NeedInput, NeedOutput, Done
}
Progress
Struct · Source
Counts for one incremental process call.
pub struct Progress {
pub input_consumed: usize
pub output_written: usize
pub status: Status
}
DecodeResult
Struct · Source
pub struct DecodeResult {
pub input_consumed: usize
pub output_written: usize
}
MAX_LEVEL
Constant · Source
pub const MAX_LEVEL: usize = 9
DEFAULT_LEVEL
Constant · Source
pub const DEFAULT_LEVEL: usize = 6
WINDOW_SIZE
Constant · Source
The largest back-reference distance, and the default decoder window.
pub const WINDOW_SIZE: usize = 32768
max_encoded_len
Function · Source
An output length that every encode level is guaranteed to fit. Blocks never exceed their stored-block size, so incompressible input grows only slightly.
pub fn max_encoded_len(input_len: usize) -> usize
WORKSPACE_LEN
Constant · Source
Words of caller storage for the LZ77 match finder and block tokens, 256 KiB. Encoders reset it on each call, so one buffer serves any number of calls.
pub const WORKSPACE_LEN: usize = HASH_SIZE + WINDOW_SIZE + TOKEN_LIMIT + 1
encode
Function · Source
Compresses input into one raw DEFLATE stream at level 0 (stored blocks) through 9 (slowest, smallest). Each block is stored, fixed-, or dynamic-Huffman, whichever is smallest, so max_encoded_len(input.len) bytes always suffice. Output contents are unspecified on error. The match finder uses WORKSPACE_LEN words on the stack; see encode_with_workspace.
pub fn encode(input: &[u8], output: &mut[u8], level: usize) -> usize!Error
encode_with_workspace
Function · Source
Like encode, with caller-owned match-finder storage of at least WORKSPACE_LEN words, which may be static and reused.
pub fn encode_with_workspace(input: &[u8], output: &mut[u8], level: usize, words: &mut[u32]) -> usize!Error
ENCODER_BUFFER_LEN
Constant · Source
Bytes of caller storage an Encoder needs: an input window and a block buffer.
pub const ENCODER_BUFFER_LEN: usize = STREAM_WINDOW + PENDING_SIZE
Encoder
Struct · Source
Incremental compressor producing one raw DEFLATE stream. It buffers up to 64 KiB of input and emits whole blocks, so output lags input until finish. Storage is borrowed so the encoder stays small and never moves its buffers: a buffer of at least ENCODER_BUFFER_LEN bytes and a workspace of at least WORKSPACE_LEN words, about 350 KiB together. Static storage suits small stacks.
pub struct Encoder {
// Private implementation fields omitted.
}
Encoder.new
Function · Source
pub fn new(level: usize, buffer: &mut[u8], words: &mut[u32]) -> Encoder!Error from(buffer, words)
Encoder.reset
Function · Source
Starts a new stream at the same level.
pub fn reset(&mut self)
Encoder.process
Function · Source
Consumes input and writes compressed output. Pass finish true once input holds the final bytes, and keep passing it, resubmitting unconsumed input, until Done. NeedInput means all input was consumed; NeedOutput means output is full. Counts cover this call only.
pub fn process(&mut self, input: &[u8], output: &mut[u8], finish: bool) -> Progress