Skip to content

Commit fd529c6

Browse files
authored
fix(zstd): fastest level now does compression (#357)
1 parent ec5f36d commit fd529c6

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,15 @@ impl Level {
254254
#[cfg(feature = "zstd")]
255255
fn into_zstd(self) -> i32 {
256256
let (fastest, best) = libzstd::compression_level_range().into_inner();
257+
258+
// NOTE: zstd's "fastest" level is -131072 which can create outputs larger than inputs.
259+
// This library chooses a "fastest" level which has a more-or-less equivalent compression
260+
// ratio to gzip's fastest mode. We still allow precise levels to go negative.
261+
// See discussion in https://github.com/Nullus157/async-compression/issues/352
262+
const OUR_FASTEST: i32 = 1;
263+
257264
match self {
258-
Self::Fastest => fastest,
265+
Self::Fastest => OUR_FASTEST,
259266
Self::Best => best,
260267
Self::Precise(quality) => quality.clamp(fastest, best),
261268
Self::Default => libzstd::DEFAULT_COMPRESSION_LEVEL,

0 commit comments

Comments
 (0)