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 { |
11 | fn total_in(&self) -> u64; |
12 | fn total_out(&self) -> u64; |
13 | } |
14 | |
15 | pub trait InflateBackend: Backend { |
16 | fn make(zlib_header: bool, window_bits: u8) -> Self; |
17 | fn decompress( |
18 | &mut self, |
19 | input: &[u8], |
20 | output: &mut [u8], |
21 | flush: FlushDecompress, |
22 | ) -> Result<Status, DecompressError>; |
23 | fn reset(&mut self, zlib_header: bool); |
24 | } |
25 | |
26 | pub trait DeflateBackend: Backend { |
27 | fn make(level: Compression, zlib_header: bool, window_bits: u8) -> Self; |
28 | fn compress( |
29 | &mut self, |
30 | input: &[u8], |
31 | output: &mut [u8], |
32 | flush: FlushCompress, |
33 | ) -> Result<Status, CompressError>; |
34 | fn reset(&mut self); |
35 | } |
36 | |
37 | // Default to Rust implementation unless explicitly opted in to a different backend. |
38 | #[cfg (feature = "any_zlib" )] |
39 | mod c; |
40 | #[cfg (feature = "any_zlib" )] |
41 | pub use self::c::*; |
42 | |
43 | #[cfg (all(not(feature = "any_zlib" ), feature = "miniz_oxide" ))] |
44 | mod rust; |
45 | #[cfg (all(not(feature = "any_zlib" ), feature = "miniz_oxide" ))] |
46 | pub use self::rust::*; |
47 | |
48 | impl std::fmt::Debug for ErrorMessage { |
49 | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
50 | self.get().fmt(f) |
51 | } |
52 | } |
53 | |