Skip to content

Commit

Permalink
snappy: add buf_size parm to compress helper fn
Browse files Browse the repository at this point in the history
  • Loading branch information
jqnatividad committed Oct 21, 2023
1 parent d48269c commit e0c0d1f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/cmd/snappy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
jobs -= 1; // save one thread for other tasks
}

compress(input_reader, output_writer, jobs)?;
compress(input_reader, output_writer, jobs, gzp::BUFSIZE * 2)?;
let compressed_bytes = if let Some(path) = &args.flag_output {
fs::metadata(path)?.len()
} else {
Expand Down Expand Up @@ -238,10 +238,16 @@ pub fn compress<R: Read, W: Write + Send + 'static>(
mut src: R,
dst: W,
jobs: usize,
buf_size: usize,
) -> CliResult<()> {
let mut writer = ParCompressBuilder::<Snap>::new()
.num_threads(jobs)?
.buffer_size(gzp::BUFSIZE)?
// the buffer size must be at least gzp::DICT_SIZE
.buffer_size(if buf_size < gzp::DICT_SIZE {
gzp::DICT_SIZE
} else {
buf_size
})?
.pin_threads(Some(0))
.from_writer(dst);
io::copy(&mut src, &mut writer)?;
Expand Down

0 comments on commit e0c0d1f

Please sign in to comment.