1#![forbid(unsafe_code)]
4#![deny(warnings)]
5#![deny(missing_docs)]
6#![cfg_attr(not(feature = "std"), no_std)]
7#![cfg_attr(feature = "nightly", feature(optimize_attribute))]
8
9use core::{error::Error, fmt};
10
11mod sink;
12pub use sink::{Sink, SliceSink};
13
14mod fastcpy;
15pub use fastcpy::slice_copy;
16
17pub const WINDOW_SIZE: usize = 64 * 1024;
21
22pub const MFLIMIT: usize = 12;
24
25pub const LAST_LITERALS: usize = 5;
27
28pub const END_OFFSET: usize = LAST_LITERALS + 1;
30
31pub const LZ4_MIN_LENGTH: usize = MFLIMIT + 1;
33
34pub const MAX_DISTANCE: usize = (1 << 16) - 1;
36
37pub const MINMATCH: usize = 4;
39
40#[derive(Debug, Clone, PartialEq, Eq)]
42#[non_exhaustive]
43pub enum DecompressError {
44 OutputTooSmall {
46 expected: usize,
48 actual: usize,
50 },
51 LiteralOutOfBounds,
53 ExpectedAnotherByte,
55 OffsetZero,
57 OffsetOutOfBounds,
59}
60
61#[derive(Debug, Clone, PartialEq, Eq)]
62#[non_exhaustive]
63pub enum CompressError {
65 OutputTooSmall,
67}
68
69impl fmt::Display for DecompressError {
70 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
71 match self {
72 DecompressError::OutputTooSmall { expected, actual } => {
73 write!(
74 f,
75 "provided output is too small for the decompressed data, actual {actual}, expected \
76 {expected}"
77 )
78 }
79 DecompressError::LiteralOutOfBounds => {
80 f.write_str("literal is out of bounds of the input")
81 }
82 DecompressError::ExpectedAnotherByte => {
83 f.write_str("expected another byte, found none")
84 }
85 DecompressError::OffsetZero => f.write_str("0 is not a valid match offset"),
86 DecompressError::OffsetOutOfBounds => {
87 f.write_str("the offset to copy is not contained in the decompressed buffer")
88 }
89 }
90 }
91}
92
93impl fmt::Display for CompressError {
94 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
95 match self {
96 CompressError::OutputTooSmall => f.write_str(
97 "output is too small for the compressed data, use get_maximum_output_size to \
98 reserve enough space",
99 ),
100 }
101 }
102}
103
104impl Error for DecompressError {}
105
106impl Error for CompressError {}