diff --git a/rc-zip-sync/src/entry_reader.rs b/rc-zip-sync/src/entry_reader.rs index a48a6df..f72e7b6 100644 --- a/rc-zip-sync/src/entry_reader.rs +++ b/rc-zip-sync/src/entry_reader.rs @@ -19,7 +19,7 @@ where pub(crate) fn new(entry: &StoredEntry, rd: R) -> Self { Self { rd, - fsm: Some(EntryFsm::new(entry.method(), entry.inner)), + fsm: Some(EntryFsm::new(entry.inner)), } } } @@ -53,7 +53,7 @@ where self.read(buf) } } - FsmResult::Done(()) => { + FsmResult::Done(_) => { // neat! Ok(0) } diff --git a/rc-zip-tokio/src/entry_reader.rs b/rc-zip-tokio/src/entry_reader.rs index c4af59b..6d7e6f7 100644 --- a/rc-zip-tokio/src/entry_reader.rs +++ b/rc-zip-tokio/src/entry_reader.rs @@ -28,7 +28,7 @@ where { Self { rd: get_reader(entry.header_offset), - fsm: Some(EntryFsm::new(entry.method(), entry.inner)), + fsm: Some(EntryFsm::new(entry.inner)), } } } @@ -78,7 +78,7 @@ where return self.poll_read(cx, buf); } } - FsmResult::Done(()) => { + FsmResult::Done(_) => { // neat! } } diff --git a/rc-zip/src/fsm/entry/mod.rs b/rc-zip/src/fsm/entry/mod.rs index db72965..4b6a12c 100644 --- a/rc-zip/src/fsm/entry/mod.rs +++ b/rc-zip/src/fsm/entry/mod.rs @@ -85,18 +85,16 @@ enum State { pub struct EntryFsm { state: State, entry: StoredEntryInner, - method: Method, buffer: Buffer, eof: bool, } impl EntryFsm { /// Create a new state machine for decompressing a zip entry - pub fn new(method: Method, entry: StoredEntryInner) -> Self { + pub fn new(entry: StoredEntryInner) -> Self { Self { state: State::ReadLocalHeader, entry, - method, buffer: Buffer::with_capacity(256 * 1024), eof: false, } @@ -131,7 +129,7 @@ impl EntryFsm { pub fn process( mut self, out: &mut [u8], - ) -> Result, Error> { + ) -> Result, Error> { tracing::trace!( state = match &self.state { State::ReadLocalHeader => "ReadLocalHeader", @@ -152,12 +150,13 @@ impl EntryFsm { let consumed = input.as_bytes().offset_from(&self.buffer.data()); tracing::trace!(local_file_header = ?header, consumed, "parsed local file header"); self.buffer.consume(consumed); + let decompressor = AnyDecompressor::new(header.method, &self.entry)?; self.state = S::ReadData { header, compressed_bytes: 0, uncompressed_bytes: 0, hasher: crc32fast::Hasher::new(), - decompressor: AnyDecompressor::new(self.method, &self.entry)?, + decompressor, }; self.process(out) } @@ -284,7 +283,7 @@ impl EntryFsm { })); } - Ok(FsmResult::Done(())) + Ok(FsmResult::Done(self.buffer)) } S::Transition => { unreachable!("the state machine should never be in the transition state")