Skip to content

Commit

Permalink
EntryFsm: give back the buffer
Browse files Browse the repository at this point in the history
Also use method from local header
  • Loading branch information
fasterthanlime committed Feb 2, 2024
1 parent c95749b commit 0803c17
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions rc-zip-sync/src/entry_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
}
}
}
Expand Down Expand Up @@ -53,7 +53,7 @@ where
self.read(buf)
}
}
FsmResult::Done(()) => {
FsmResult::Done(_) => {
// neat!
Ok(0)
}
Expand Down
4 changes: 2 additions & 2 deletions rc-zip-tokio/src/entry_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
}
}
}
Expand Down Expand Up @@ -78,7 +78,7 @@ where
return self.poll_read(cx, buf);
}
}
FsmResult::Done(()) => {
FsmResult::Done(_) => {
// neat!
}
}
Expand Down
11 changes: 5 additions & 6 deletions rc-zip/src/fsm/entry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -131,7 +129,7 @@ impl EntryFsm {
pub fn process(
mut self,
out: &mut [u8],
) -> Result<FsmResult<(Self, DecompressOutcome), ()>, Error> {
) -> Result<FsmResult<(Self, DecompressOutcome), Buffer>, Error> {
tracing::trace!(
state = match &self.state {
State::ReadLocalHeader => "ReadLocalHeader",
Expand All @@ -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)
}
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 0803c17

Please sign in to comment.