compress_lib/stream.rs
1//! The result of one streaming call.
2
3/// Where a streaming engine stopped.
4///
5/// # Examples
6///
7/// ```
8/// use compress_lib::deflate::{Inflater, Status};
9///
10/// let mut out = [0u8; 8];
11/// let p = Inflater::new().decompress(&[0xCB, 0x48], &mut out)?;
12/// assert_eq!(p.status, Status::NeedsInput);
13/// # Ok::<(), compress_lib::Error>(())
14/// ```
15#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
16#[non_exhaustive]
17pub enum Status {
18 /// All input was consumed and the stream goes on: call again with more.
19 NeedsInput,
20 /// The output buffer is full: call again with more room and the input
21 /// not yet consumed.
22 NeedsOutput,
23 /// The stream (or, for encoders, the requested flush) is complete.
24 Done,
25}
26
27/// What one streaming call did.
28///
29/// # Examples
30///
31/// ```
32/// use compress_lib::deflate::{Inflater, Status};
33///
34/// let mut out = [0u8; 8];
35/// let p = Inflater::new().finish(&[0xCB, 0x48, 0xCD, 0xC9, 0xC9, 0x07, 0x00], &mut out)?;
36/// assert_eq!((p.consumed, p.produced, p.status), (7, 5, Status::Done));
37/// # Ok::<(), compress_lib::Error>(())
38/// ```
39#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
40#[non_exhaustive]
41pub struct Progress {
42 /// Bytes of input consumed (never more than the input given).
43 pub consumed: usize,
44 /// Bytes of output produced (never more than the room given).
45 pub produced: usize,
46 /// Where the engine stopped.
47 pub status: Status,
48}
49
50impl Progress {
51 pub(crate) const fn new(consumed: usize, produced: usize, status: Status) -> Self {
52 Self {
53 consumed,
54 produced,
55 status,
56 }
57 }
58}