Struct rc_zip::fsm::ArchiveFsm
source · pub struct ArchiveFsm { /* private fields */ }
Expand description
ArchiveFsm parses a valid zip archive into an Archive. In particular, this struct finds an end of central directory record, parses the entire central directory, detects text encoding, and normalizes metadata.
The loop is as follows:
- Call Self::wants_read to check if more data is needed.
- If it returns
Some(offset)
, read the file at that offset into Self::space and then call Self::fill with the number of bytes read. - Call Self::process to process the data.
- If it returns FsmResult::Continue, loop back to the first step.
Look at the integration tests or rc-zip-sync for concrete examples.
Implementations§
source§impl ArchiveFsm
impl ArchiveFsm
sourcepub fn wants_read(&self) -> Option<u64>
pub fn wants_read(&self) -> Option<u64>
If this returns Some(offset)
, the caller should read data from
offset
into Self::space — without forgetting to call
Self::fill with the number of bytes written.
sourcepub fn process(self) -> Result<FsmResult<Self, Archive>, Error>
pub fn process(self) -> Result<FsmResult<Self, Archive>, Error>
Process buffered data
Errors returned from this function are caused by invalid zip archives, unsupported format quirks, or implementation bugs - never I/O errors.
A result of FsmResult::Continue gives back ownership of the state machine and indicates the I/O loop should continue, starting with Self::wants_read.
A result of FsmResult::Done consumes the state machine and returns a fully-parsed Archive.
sourcepub fn space(&mut self) -> &mut [u8] ⓘ
pub fn space(&mut self) -> &mut [u8] ⓘ
Returns a mutable slice with all the available space to write to.
After writing to this, call Self::fill with the number of bytes written.
sourcepub fn fill(&mut self, count: usize) -> usize
pub fn fill(&mut self, count: usize) -> usize
After having written data to Self::space, call this to indicate how many bytes were written.