packkit/codec

Byte-to-byte compression formats and their errors.

Pass a Codec to packkit.compress and packkit.decompress, or list codecs in a packkit.Recipe to compress a whole archive.

Types

A compression format.

pub type Codec {
  Identity
  Deflate
  Zlib
  Gzip
  Lz4
  Snappy
  Bzip2
  Lzw
  Xz
  Zstd
  Brotli
}

Constructors

  • Identity

    Leaves the bytes unchanged.

  • Deflate

    Raw DEFLATE (RFC 1951) with no header.

  • Zlib

    zlib (RFC 1950).

  • Gzip

    gzip (RFC 1952). Use packkit/gzip to read or write the header.

  • Lz4

    LZ4 frame format.

  • Snappy

    Snappy framing format.

  • Bzip2
  • Lzw

    Unix compress (.Z).

  • Xz
  • Zstd

    Zstandard.

  • Brotli

    Brotli (RFC 7932).

Errors from compressing and decompressing.

pub type CodecError {
  InvalidData(message: String)
  LimitExceeded(limit: String, actual: Int)
  DictionaryRequired
  Unsupported(feature: String)
}

Constructors

  • InvalidData(message: String)

    The bytes are not a valid stream of the requested format.

  • LimitExceeded(limit: String, actual: Int)

    The input went over one of the Limits.

  • DictionaryRequired

    The zlib stream was made with a preset dictionary, which packkit does not support.

  • Unsupported(feature: String)

    The stream is valid but uses a feature packkit does not read.

Values

pub fn error_to_string(error: CodecError) -> String

Describes an error in one line, for logs and command-line output.

Examples

error_to_string(LimitExceeded(limit: "max_input_bytes", actual: 70_000_000))
// -> "codec: limit max_input_bytes exceeded (actual 70000000)"
✨ Search Document