pub struct Reader<R, D> {
reader: R,
operation: D,
state: State,
single_frame: bool,
finished_frame: bool,
started: bool,
}Expand description
Fields§
§reader: R§operation: D§state: State§single_frame: bool§finished_frame: bool§started: boolImplementations§
Source§impl<R, D> Reader<R, D>
impl<R, D> Reader<R, D>
Sourcepub fn new(reader: R, operation: D) -> Self
pub fn new(reader: R, operation: D) -> Self
Creates a new Reader.
reader will be used to pull input data for the given operation.
Sourcepub fn set_single_frame(&mut self)
pub fn set_single_frame(&mut self)
Sets self to stop after the first decoded frame.
Sourcepub fn operation_mut(&mut self) -> &mut D
pub fn operation_mut(&mut self) -> &mut D
Returns a mutable reference to the underlying operation.
Sourcepub fn reader_mut(&mut self) -> &mut R
pub fn reader_mut(&mut self) -> &mut R
Returns a mutable reference to the underlying reader.
Sourcepub fn into_inner(self) -> R
pub fn into_inner(self) -> R
Returns the inner reader.
Source§impl<R, D> Reader<R, D>
impl<R, D> Reader<R, D>
Sourcepub fn finish_frame(&mut self) -> Result<()>
pub fn finish_frame(&mut self) -> Result<()>
Consume the rest of the current frame from the underlying reader.
Once all the decoded data has been read, zstd may still not have consumed the tail of the frame: it can produce the last of the output before reading the frame epilogue. The underlying reader is then left pointing somewhere inside the frame rather than just after it.
This feeds zstd the input it still needs, with no room for output, so the reader ends up positioned exactly at the end of the frame.
It stops there: it will not start decoding whatever follows, so a stream of concatenated frames keeps its remaining frames, and trailing non-zstd data is left untouched.
This is a no-op if the current frame is already complete, or if no frame has been started yet, so it will not read from the underlying reader in those cases.
Trait Implementations§
Source§impl<R, D> Read for Reader<R, D>
impl<R, D> Read for Reader<R, D>
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>
Reads everything the operation produces into buf.
The default implementation has an awkward ending: when the output happens to fill the vector exactly, it doubles the capacity and reallocates - copying everything decoded so far - then reads zero bytes and truncates back. Probing with a small stack buffer first establishes there is nothing left without paying for that. Whether the saving shows up depends on the allocator: one that can grow a large block in place makes it cheap, one that has to copy does not.
This should be deleted once Read::read_buf is stable. std can then
fill spare capacity without initializing it first, which removes both
the reallocation and the zeroing this does by hand, and its version
will be the better one.
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_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)