pub trait Decoder {
// Required methods
fn decode(
&mut self,
input: &[u8],
output: &mut [u8],
) -> Result<(Progress, Status), Error>;
fn finish(&mut self, output: &mut [u8]) -> Result<(Progress, Status), Error>;
fn reset(&mut self);
fn discard_output(
&mut self,
input: &[u8],
n: usize,
) -> Result<(Progress, Status), Error>;
}Expand description
A streaming decompressor.
Symmetric to Encoder plus an optional discard_output.
§Post-error state
After any Err(_) return, the decoder is poisoned: subsequent calls
without an intervening reset are unspecified and may
return further errors. Some decoders (deflate, zlib, gzip, …) explicitly
track a poison flag and return Error::Corrupt until reset.
Required Methods§
fn decode( &mut self, input: &[u8], output: &mut [u8], ) -> Result<(Progress, Status), Error>
fn finish(&mut self, output: &mut [u8]) -> Result<(Progress, Status), Error>
Sourcefn reset(&mut self)
fn reset(&mut self)
See Encoder::reset — configuration is preserved.
Sourcefn discard_output(
&mut self,
input: &[u8],
n: usize,
) -> Result<(Progress, Status), Error>
fn discard_output( &mut self, input: &[u8], n: usize, ) -> Result<(Progress, Status), Error>
Advance the decompressed stream by up to n decompressed bytes
without writing them to the caller.
The signature still takes input because the decoder still needs
compressed bytes to advance its state; the n parameter just tells
the decoder to discard those decompressed bytes rather than emit
them. Best-effort: stops at input exhaustion or after exactly n
bytes have been discarded, whichever comes first.
Useful when listing files in a .tar.gz without materialising
their contents.
The default implementation just runs decode into
a small scratch buffer and discards the result; algorithms that can
short-circuit (e.g. through stored / uncompressed blocks) are
encouraged to override.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".