Skip to content

Commit

Permalink
Re-use read buf
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Jan 26, 2024
1 parent 849ee09 commit 52ce814
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions crates/rc-zip/src/reader/sync/entry_reader/lzma_dec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct LzmaDecoderAdapter<R> {
input: R,
total_write_count: u64,
state: LzmaDecoderState,
read_buf: Vec<u8>,
}

impl<R> Read for LzmaDecoderAdapter<R>
Expand All @@ -28,10 +29,7 @@ where

match state {
LzmaDecoderState::Writing(mut stream) => {
// FIXME: all this is terribly wasteful, I'm just trying to see if it
// will decompress
let mut read_buf = vec![0u8; 8192];
let bytes_read = self.input.read(&mut read_buf)?;
let bytes_read = self.input.read(&mut self.read_buf)?;
if bytes_read == 0 {
// we're EOF: finish and move on to draining
self.state = LzmaDecoderState::Draining(stream.finish()?);
Expand All @@ -43,7 +41,7 @@ where
"Writing {} bytes to lzma_rs::decompress::Stream",
bytes_read
);
if let Err(e) = stream.write_all(&read_buf[..bytes_read]) {
if let Err(e) = stream.write_all(&self.read_buf[..bytes_read]) {
if e.kind() == std::io::ErrorKind::WriteZero {
// that's expected actually! from the lzma-rs tests:
//
Expand Down Expand Up @@ -159,5 +157,6 @@ pub(crate) fn mk_decoder(
input: r,
total_write_count: 0,
state: LzmaDecoderState::Writing(Box::new(stream)),
read_buf: vec![0u8; 8192],
})
}

0 comments on commit 52ce814

Please sign in to comment.