stream_unpack/decompress/
deflate.rs

1use std::fmt::Debug;
2
3use inflate::InflateStream;
4
5use super::{Decompressor, DecompressionError};
6
7/// Simple wrapper around an [InflateStream]
8pub struct DeflateDecompressor(InflateStream);
9
10impl Debug for DeflateDecompressor {
11    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
12        f.debug_struct("DeflateDecompressor")
13            .finish()
14    }
15}
16
17impl Default for DeflateDecompressor {
18    /// Identical to [DeflateDecompressor::new]
19    fn default() -> Self {
20        Self::new()    
21    }
22}
23
24impl Decompressor for DeflateDecompressor {
25    fn update(&mut self, data: &[u8]) -> Result<(usize, &[u8]), DecompressionError> {
26        self.0.update(data)
27            .map_err(DecompressionError::Generic)
28    }
29}
30
31impl DeflateDecompressor {
32    /// Creates a new DeflateDecompressor, with a new [InflateStream]
33    pub fn new() -> Self {
34        Self(InflateStream::new())
35    }
36}