pub struct Decoder<R> { /* private fields */ }std only.Expand description
Decompresses a zstd stream from a reader (std::io::Read), frame after
frame, like the zstd crate’s Decoder.
use std::io::Read;
let mut out = String::new();
zstd_native::Decoder::new(compressed).read_to_string(&mut out)?;
assert_eq!(out, "hello");Input that ends inside a frame is an io::ErrorKind::UnexpectedEof
error; corrupt input is io::ErrorKind::InvalidData (the source is an
Error). Empty input is zero frames: empty output, as with
libzstd (the zstd crate’s reader reports an error there instead).
read_to_end (and read_to_string) decode
straight into the Vec, growing it (reserving a frame’s content size
up front, up to the window limit), without the window buffer and the
copy out of it that read needs.
Implementations§
Source§impl<R: Read> Decoder<BufReader<R>>
impl<R: Read> Decoder<BufReader<R>>
Sourcepub fn new(reader: R) -> Self
pub fn new(reader: R) -> Self
Reads from reader through a buffer (use with_buffer
for a reader that already buffers, such as a &[u8]).
Source§impl<R: BufRead> Decoder<R>
impl<R: BufRead> Decoder<R>
Sourcepub fn with_buffer(reader: R) -> Self
pub fn with_buffer(reader: R) -> Self
Reads from a buffered reader.
Sourcepub fn with_dictionary(reader: R, dict: Dictionary) -> Self
pub fn with_dictionary(reader: R, dict: Dictionary) -> Self
Reads from a buffered reader, using dict for every frame.
Sourcepub fn set_window_log_max(&mut self, log: u32)
pub fn set_window_log_max(&mut self, log: u32)
Sets the largest window accepted (see StreamDecoder::set_window_log_max).
Sourcepub fn get_mut(&mut self) -> &mut R
pub fn get_mut(&mut self) -> &mut R
The underlying reader, mutably (reading from it directly loses the decoder’s place in the stream).
Sourcepub fn into_inner(self) -> R
pub fn into_inner(self) -> R
Returns the underlying reader.
Trait Implementations§
Source§impl<R: BufRead> Read for Decoder<R>
impl<R: BufRead> Read for Decoder<R>
Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
Decodes straight into buf, growing it (by a frame’s content size
when the header gives it), without the window buffer and the copy
out of it that read needs.
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize>
buf. Read more1.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.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)