]> git.proxmox.com Git - rustc.git/blob - vendor/gix-features/src/zlib/mod.rs
New upstream version 1.70.0+dfsg2
[rustc.git] / vendor / gix-features / src / zlib / mod.rs
1 pub use flate2::{Decompress, Status};
2
3 /// non-streaming interfaces for decompression
4 pub mod inflate {
5 /// The error returned by various [Inflate methods][super::Inflate]
6 #[derive(Debug, thiserror::Error)]
7 #[allow(missing_docs)]
8 pub enum Error {
9 #[error("Could not write all bytes when decompressing content")]
10 WriteInflated(#[from] std::io::Error),
11 #[error("Could not decode zip stream, status was '{0:?}'")]
12 Inflate(#[from] flate2::DecompressError),
13 #[error("The zlib status indicated an error, status was '{0:?}'")]
14 Status(flate2::Status),
15 }
16 }
17
18 /// Decompress a few bytes of a zlib stream without allocation
19 pub struct Inflate {
20 /// The actual decompressor doing all the work.
21 pub state: Decompress,
22 }
23
24 impl Default for Inflate {
25 fn default() -> Self {
26 Inflate {
27 state: Decompress::new(true),
28 }
29 }
30 }
31
32 impl Inflate {
33 /// Run the decompressor exactly once. Cannot be run multiple times
34 pub fn once(&mut self, input: &[u8], out: &mut [u8]) -> Result<(flate2::Status, usize, usize), inflate::Error> {
35 let before_in = self.state.total_in();
36 let before_out = self.state.total_out();
37 let status = self.state.decompress(input, out, flate2::FlushDecompress::None)?;
38 Ok((
39 status,
40 (self.state.total_in() - before_in) as usize,
41 (self.state.total_out() - before_out) as usize,
42 ))
43 }
44 }
45
46 ///
47 pub mod stream;