tinybz2 0.1.0

Minimal-memory bz2 compressor/decompressor for embedded targets
Documentation
//! Error types for tinybz2.

/// Errors that can occur during bz2 compression or decompression.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Error {
    /// Block size parameter out of range (must be 1..=9).
    BadBlockSize,
    /// Output buffer too small to hold the result.
    OutputOverflow,
    /// Input data is not valid bz2 format.
    BadMagic,
    /// Corrupted block header.
    BadBlockHeader,
    /// CRC mismatch on a decompressed block.
    BlockCrcMismatch,
    /// CRC mismatch on the entire stream.
    StreamCrcMismatch,
    /// Huffman table is malformed or exceeds maximum code length.
    BadHuffmanTable,
    /// Selector index out of range.
    BadSelector,
    /// Symbol value out of range during MTF decode.
    BadMtfValue,
    /// Run-length encoding produced more data than the block can hold.
    RleOverflow,
    /// BWT primary index out of range.
    BadBwtIndex,
    /// Unexpected end of input data.
    UnexpectedEof,
    /// Data after end-of-stream marker (trailing garbage).
    TrailingData,
    /// Internal: block buffer is full.
    BlockFull,
}

impl core::fmt::Display for Error {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Error::BadBlockSize => write!(f, "block size must be 1..=9"),
            Error::OutputOverflow => write!(f, "output buffer too small"),
            Error::BadMagic => write!(f, "not a bz2 stream"),
            Error::BadBlockHeader => write!(f, "corrupted block header"),
            Error::BlockCrcMismatch => write!(f, "block CRC mismatch"),
            Error::StreamCrcMismatch => write!(f, "stream CRC mismatch"),
            Error::BadHuffmanTable => write!(f, "malformed Huffman table"),
            Error::BadSelector => write!(f, "selector index out of range"),
            Error::BadMtfValue => write!(f, "MTF symbol out of range"),
            Error::RleOverflow => write!(f, "RLE output exceeds block size"),
            Error::BadBwtIndex => write!(f, "BWT primary index out of range"),
            Error::UnexpectedEof => write!(f, "unexpected end of input"),
            Error::TrailingData => write!(f, "trailing data after stream"),
            Error::BlockFull => write!(f, "block buffer full"),
        }
    }
}