#![forbid(unsafe_code)]
#![deny(rust_2018_idioms, nonstandard_style, future_incompatible)]
#![cfg_attr(docsrs, feature(doc_cfg))]
mod buffer;
mod huffman_tree;
mod inflater_managed;
mod input_buffer;
mod output_window;
mod stream;
#[cfg(feature = "checkpoint")]
pub use inflater_managed::checkpoint;
pub use inflater_managed::InflaterManaged;
pub use stream::Deflate64Decoder;
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
enum BlockType {
Uncompressed = 0,
Static = 1,
Dynamic = 2,
}
impl BlockType {
pub fn from_int(int: u16) -> Option<BlockType> {
match int {
0 => Some(Self::Uncompressed),
1 => Some(Self::Static),
2 => Some(Self::Dynamic),
_ => None,
}
}
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
enum InflaterState {
ReadingBFinal = 2,
ReadingBType = 3,
ReadingNumLitCodes = 4,
ReadingNumDistCodes = 5,
ReadingNumCodeLengthCodes = 6,
ReadingCodeLengthCodes = 7,
ReadingTreeCodesBefore = 8,
ReadingTreeCodesAfter = 9,
DecodeTop = 10,
HaveInitialLength = 11,
HaveFullLength = 12,
HaveDistCode = 13,
UncompressedAligning = 15,
UncompressedByte1 = 16,
UncompressedByte2 = 17,
UncompressedByte3 = 18,
UncompressedByte4 = 19,
DecodingUncompressed = 20,
Done = 24,
DataErrored = 100,
}
impl std::ops::Sub for InflaterState {
type Output = u8;
fn sub(self, rhs: Self) -> Self::Output {
self as u8 - rhs as u8
}
}
fn array_copy<T: Copy>(source: &[T], dst: &mut [T], length: usize) {
dst[..length].copy_from_slice(&source[..length]);
}
fn array_copy1<T: Copy>(
source: &[T],
source_index: usize,
dst: &mut [T],
dst_index: usize,
length: usize,
) {
dst[dst_index..][..length].copy_from_slice(&source[source_index..][..length]);
}
#[derive(Debug)]
pub struct InflateResult {
pub bytes_consumed: usize,
pub bytes_written: usize,
pub data_error: bool,
}
impl InflateResult {
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
Self {
bytes_consumed: 0,
bytes_written: 0,
data_error: false,
}
}
}
#[derive(Debug)]
enum InternalErr {
DataNeeded,
DataError,
}