#![forbid(unsafe_code)]
#![deny(warnings)]
#![deny(missing_docs)]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(feature = "nightly", feature(optimize_attribute))]
use core::{error::Error, fmt};
mod sink;
pub use sink::{Sink, SliceSink};
mod fastcpy;
pub use fastcpy::slice_copy;
pub const WINDOW_SIZE: usize = 64 * 1024;
pub const MFLIMIT: usize = 12;
pub const LAST_LITERALS: usize = 5;
pub const END_OFFSET: usize = LAST_LITERALS + 1;
pub const LZ4_MIN_LENGTH: usize = MFLIMIT + 1;
pub const MAX_DISTANCE: usize = (1 << 16) - 1;
pub const MINMATCH: usize = 4;
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum DecompressError {
OutputTooSmall {
expected: usize,
actual: usize,
},
LiteralOutOfBounds,
ExpectedAnotherByte,
OffsetZero,
OffsetOutOfBounds,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum CompressError {
OutputTooSmall,
}
impl fmt::Display for DecompressError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
DecompressError::OutputTooSmall { expected, actual } => {
write!(
f,
"provided output is too small for the decompressed data, actual {actual}, expected \
{expected}"
)
}
DecompressError::LiteralOutOfBounds => {
f.write_str("literal is out of bounds of the input")
}
DecompressError::ExpectedAnotherByte => {
f.write_str("expected another byte, found none")
}
DecompressError::OffsetZero => f.write_str("0 is not a valid match offset"),
DecompressError::OffsetOutOfBounds => {
f.write_str("the offset to copy is not contained in the decompressed buffer")
}
}
}
}
impl fmt::Display for CompressError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
CompressError::OutputTooSmall => f.write_str(
"output is too small for the compressed data, use get_maximum_output_size to \
reserve enough space",
),
}
}
}
impl Error for DecompressError {}
impl Error for CompressError {}