Skip to content

Commit

Permalink
use default compression level for zstd
Browse files Browse the repository at this point in the history
  • Loading branch information
martinabeleda authored and Quentin Perez committed Sep 21, 2023
1 parent 1fb1806 commit 23ab9e2
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions tonic/src/codec/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ pub(crate) fn compress(
) -> Result<(), std::io::Error> {
let capacity = ((len / BUFFER_SIZE) + 1) * BUFFER_SIZE;
out_buf.reserve(capacity);
let mut out_writer = bytes::BufMut::writer(out_buf);

match encoding {
#[cfg(feature = "gzip")]
Expand All @@ -211,19 +212,15 @@ pub(crate) fn compress(
// FIXME: support customizing the compression level
flate2::Compression::new(6),
);
let mut out_writer = bytes::BufMut::writer(out_buf);

std::io::copy(&mut gzip_encoder, &mut out_writer)?;
}
#[cfg(feature = "zstd")]
CompressionEncoding::Zstd => {
let mut zstd_encoder = Encoder::new(
&decompressed_buf[0..len],
// FIXME: support customizing the compression level
0,
zstd::DEFAULT_COMPRESSION_LEVEL,
)?;
let mut out_writer = bytes::BufMut::writer(out_buf);

std::io::copy(&mut zstd_encoder, &mut out_writer)?;
}
}
Expand All @@ -244,20 +241,17 @@ pub(crate) fn decompress(
let estimate_decompressed_len = len * 2;
let capacity = ((estimate_decompressed_len / BUFFER_SIZE) + 1) * BUFFER_SIZE;
out_buf.reserve(capacity);
let mut out_writer = bytes::BufMut::writer(out_buf);

match encoding {
#[cfg(feature = "gzip")]
CompressionEncoding::Gzip => {
let mut gzip_decoder = GzDecoder::new(&compressed_buf[0..len]);
let mut out_writer = bytes::BufMut::writer(out_buf);

std::io::copy(&mut gzip_decoder, &mut out_writer)?;
}
#[cfg(feature = "zstd")]
CompressionEncoding::Zstd => {
let mut zstd_decoder = Decoder::new(&compressed_buf[0..len])?;
let mut out_writer = bytes::BufMut::writer(out_buf);

std::io::copy(&mut zstd_decoder, &mut out_writer)?;
}
}
Expand Down

0 comments on commit 23ab9e2

Please sign in to comment.