From f52c62894981981ba54d5bc3d9aed1d5d240dc43 Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Fri, 12 Jan 2024 10:36:09 +0100 Subject: [PATCH] allow the full range of compression levels for zstd --- crates/rattler_package_streaming/src/write.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/crates/rattler_package_streaming/src/write.rs b/crates/rattler_package_streaming/src/write.rs index fd6a9acc5..2a96bc5c9 100644 --- a/crates/rattler_package_streaming/src/write.rs +++ b/crates/rattler_package_streaming/src/write.rs @@ -39,22 +39,22 @@ pub enum CompressionLevel { #[default] Default, /// Use a numeric compression level (zstd: 1-22, bzip2: 1-9) - Numeric(u32), + Numeric(i32), } impl CompressionLevel { fn to_zstd_level(self) -> Result { match self { - CompressionLevel::Lowest => Ok(1), + CompressionLevel::Lowest => Ok(-7), CompressionLevel::Highest => Ok(22), CompressionLevel::Default => Ok(15), CompressionLevel::Numeric(n) => { - if (1..=22).contains(&n) { - Ok(n as i32) + if (-7..=22).contains(&n) { + Ok(n) } else { Err(std::io::Error::new( std::io::ErrorKind::InvalidInput, - "zstd compression level must be between 1 and 22", + "zstd compression level must be between -7 and 22", )) } } @@ -67,7 +67,8 @@ impl CompressionLevel { CompressionLevel::Default | CompressionLevel::Highest => Ok(bzip2::Compression::new(9)), CompressionLevel::Numeric(n) => { if (1..=9).contains(&n) { - Ok(bzip2::Compression::new(n)) + // this conversion from i32 to u32 cannot panic because of the check above + Ok(bzip2::Compression::new(n.try_into().unwrap())) } else { Err(std::io::Error::new( std::io::ErrorKind::InvalidInput,