rc_zip/fsm/mod.rs
1//! State machines built atop parsers, ready to bring your own I/O with.
2//!
3//! Parsers are just part of the puzzle when it comes to zip files: finding the
4//! central directory is non-trivial and involves seeking around the input:
5//! [ArchiveFsm] provides a state machine to handle this.
6//!
7//! Similarly, reading an entry involves reading the local header, then the
8//! data (while calculating the CRC32), then the data descriptor, and then
9//! checking whether the uncompressed size and CRC32 match the values in the
10//! central directory.
11
12macro_rules! transition {
13 ($state: expr => ($pattern: pat) $body: expr) => {
14 $state = if let $pattern = std::mem::take(&mut $state) {
15 $body
16 } else {
17 unreachable!()
18 };
19 };
20}
21
22mod archive;
23pub use archive::ArchiveFsm;
24
25mod entry;
26pub use entry::{DecompressOutcome, EntryFsm};
27
28/// Indicates whether or not the state machine has completed its work
29pub enum FsmResult<M, R> {
30 /// The I/O loop needs to continue, the state machine is given back.
31 Continue(M),
32
33 /// The state machine is done, and the result is returned.
34 Done(R),
35}