Skip to content

Commit

Permalink
fix take_drain to do what it says on the tin
Browse files Browse the repository at this point in the history
  • Loading branch information
KillingSpark committed Dec 23, 2024
1 parent 2cec9cf commit 7be4381
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions src/bin/zstd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ fn main() {

if flags.is_empty() {
let mut encoder = FrameCompressor::new(CompressionLevel::Fastest);
let mut output = Vec::new();
encoder.set_drain(&mut output);
encoder.set_drain(Vec::new());

for path in file_paths {
let start_instant = Instant::now();
Expand All @@ -173,10 +172,8 @@ fn main() {
last_percent: 0,
};
encoder.set_source(file);

encoder.drain_mut().unwrap().clear();
encoder.compress();
let output = encoder.drain_mut().unwrap();
let mut output: Vec<_> = encoder.take_drain().unwrap();
println!(
"Compressed {path:} from {} to {} ({}%) took {}ms",
input_len,
Expand All @@ -188,6 +185,8 @@ fn main() {
},
start_instant.elapsed().as_millis()
);
output.clear();
encoder.set_drain(output);
}
} else {
decompress(&flags, &file_paths);
Expand Down
4 changes: 2 additions & 2 deletions src/encoding/frame_compressor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ impl<R: Read, W: Write, M: Matcher> FrameCompressor<R, W, M> {
}

/// Retrieve the drain
pub fn take_drain(&mut self) -> Option<&mut W> {
self.compressed_data.as_mut()
pub fn take_drain(&mut self) -> Option<W> {
self.compressed_data.take()
}

/// Before calling [FrameCompressor::compress] you can replace the matcher
Expand Down

0 comments on commit 7be4381

Please sign in to comment.