1 //! This module contains backend-specific code. 2 3 use crate::mem::{CompressError, DecompressError, FlushCompress, FlushDecompress, Status}; 4 use crate::Compression; 5 6 /// Traits specifying the interface of the backends. 7 /// 8 /// Sync + Send are added as a condition to ensure they are available 9 /// for the frontend. 10 pub trait Backend: Sync + Send { total_in(&self) -> u6411 fn total_in(&self) -> u64; total_out(&self) -> u6412 fn total_out(&self) -> u64; 13 } 14 15 pub trait InflateBackend: Backend { make(zlib_header: bool, window_bits: u8) -> Self16 fn make(zlib_header: bool, window_bits: u8) -> Self; decompress( &mut self, input: &[u8], output: &mut [u8], flush: FlushDecompress, ) -> Result<Status, DecompressError>17 fn decompress( 18 &mut self, 19 input: &[u8], 20 output: &mut [u8], 21 flush: FlushDecompress, 22 ) -> Result<Status, DecompressError>; reset(&mut self, zlib_header: bool)23 fn reset(&mut self, zlib_header: bool); 24 } 25 26 pub trait DeflateBackend: Backend { make(level: Compression, zlib_header: bool, window_bits: u8) -> Self27 fn make(level: Compression, zlib_header: bool, window_bits: u8) -> Self; compress( &mut self, input: &[u8], output: &mut [u8], flush: FlushCompress, ) -> Result<Status, CompressError>28 fn compress( 29 &mut self, 30 input: &[u8], 31 output: &mut [u8], 32 flush: FlushCompress, 33 ) -> Result<Status, CompressError>; reset(&mut self)34 fn reset(&mut self); 35 } 36 37 // Default to Rust implementation unless explicitly opted in to a different backend. 38 cfg_if::cfg_if! { 39 if #[cfg(any(feature = "miniz-sys", feature = "any_zlib"))] { 40 mod c; 41 pub use self::c::*; 42 } else { 43 mod rust; 44 pub use self::rust::*; 45 } 46 } 47