pub struct Reader { /* private fields */ }
Expand description
A sans-io reader state machine.
Implementations§
source§impl Reader
impl Reader
sourcepub fn space(&mut self) -> &mut [u8] ⓘ
pub fn space(&mut self) -> &mut [u8] ⓘ
Get a reference to the read buffer part where new data should be written.
You should indicate how many bytes were written with fill
.
sourcepub fn available_data(&self) -> usize
pub fn available_data(&self) -> usize
Get the amount of data currently in the buffer.
sourcepub fn finish_seek(&mut self)
pub fn finish_seek(&mut self)
Tell the state machine that the seek it requested if finished.
This will clear any buffered bytes.
§Panics
This will panic if a seek was not requested.
sourcepub fn step_read_header(&mut self) -> Result<ReaderAction<()>, Error>
pub fn step_read_header(&mut self) -> Result<ReaderAction<()>, Error>
Step the state machine, performing the action of reading and validating the header.
If the header has already been read, Ok(ReaderAction::Done(()))
is returned and no work is performed.
Calling this method is optional.
The state machine will automatically read the header is if has not been read.
This will never request a seek.
sourcepub fn step_read_file_header(
&mut self,
) -> Result<ReaderAction<FileHeader>, Error>
pub fn step_read_file_header( &mut self, ) -> Result<ReaderAction<FileHeader>, Error>
Step the state machine, performing the action of reading the next file header.
This will read the header if it has not been read already.
This may request a seek.
If you want to skip over the file data, call this again after it returns ReaderAction::Done
.
sourcepub fn step_read_file_data(
&mut self,
output_buffer: &mut [u8],
) -> Result<ReaderAction<usize>, Error>
pub fn step_read_file_data( &mut self, output_buffer: &mut [u8], ) -> Result<ReaderAction<usize>, Error>
Read file data.
This will read the header if it has not already been read.
This will return Ok(ReaderAction::Done(0))
if a file header has not been read.
This will never request a seek.