pub struct Decoder<R: Read> { /* private fields */ }Expand description
Streaming decompressor implementing std::io::Read.
Pulls compressed bytes from the inner reader and yields decompressed
bytes. Reads until the inner reader ends, so concatenated archives
decode as one stream; on a source that stays open after one frame,
set Decoder::multistream to false. Returns
io::ErrorKind::UnexpectedEof if the inner reader is drained before the
ZXC footer is reached.
Decoder is single-threaded; one stream per reader.
§Example
use std::io::Read;
use zxc::Decoder;
let frame: &[u8] = &[]; // a ZXC frame
let mut dec = Decoder::new(frame).unwrap();
let mut buf = Vec::new();
dec.read_to_end(&mut buf).unwrap();Implementations§
Source§impl<R: Read> Decoder<R>
impl<R: Read> Decoder<R>
Sourcepub fn new(reader: R) -> Result<Self, Error>
pub fn new(reader: R) -> Result<Self, Error>
Creates a decoder with default decompression options: checksums are verified when a frame carries them.
Sourcepub fn with_options(
reader: R,
opts: Option<&DecompressOptions>,
) -> Result<Self, Error>
pub fn with_options( reader: R, opts: Option<&DecompressOptions>, ) -> Result<Self, Error>
Creates a decoder honouring opts.
Sourcepub fn multistream(self, enabled: bool) -> Self
pub fn multistream(self, enabled: bool) -> Self
Decodes concatenated archives as one stream (true, the default), or
stops after the first frame, as on a source that stays open after it.
Bytes read ahead past that frame are then lost to the caller.
Sourcepub fn into_inner(self) -> R
pub fn into_inner(self) -> R
Consumes the decoder and returns the inner reader.
Trait Implementations§
Source§impl<R: Read> Read for Decoder<R>
impl<R: Read> Read for Decoder<R>
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(
&mut self,
cursor: BorrowedCursor<'_, u8>,
) -> Result<(), Error>
fn read_buf_exact( &mut self, cursor: BorrowedCursor<'_, u8>, ) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R> ⓘ
fn chain<R>(self, next: R) -> Chain<Self, R> ⓘ
1.0.0 · Source§fn take(self, limit: u64) -> Take<Self> ⓘwhere
Self: Sized,
fn take(self, limit: u64) -> Take<Self> ⓘwhere
Self: Sized,
limit bytes from it. Read moreSource§fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
read_array)