From cffc3ce991d31fe12416b2e6cc236118a80842d6 Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Mon, 20 Apr 2020 12:13:05 +0100 Subject: [PATCH] Add warning for level > 3 for non-zlib It's not obvious immediately that these levels don't have any effect on libdeflater and Zopfli, since they don't iterate over zlib-specific fine-tuned options. Hence, show warning so that user knows they're getting "downgraded" to level 3. --- src/main.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8777449d..aba4856c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -321,16 +321,13 @@ fn parse_opts_into_struct( .init() .unwrap(); - let mut opts = if let Some(x) = matches.value_of("optimization") { - if let Ok(opt) = x.parse::() { - Options::from_preset(opt) - } else { - unreachable!() - } - } else { - Options::default() + let level = match matches.value_of("optimization") { + Some(x) => x.parse::().unwrap(), + None => 2, }; + let mut opts = Options::from_preset(level); + if let Some(x) = matches.value_of("interlace") { opts.interlace = x.parse::().ok(); } @@ -494,6 +491,17 @@ fn parse_opts_into_struct( } } + if level > 3 { + match opts.deflate { + Deflaters::Zlib { .. } => {} + _ => { + warn!( + "Level 4 and above are equivalent to level 3 for compressors other than zlib" + ); + } + } + } + if let Some(x) = matches.value_of("threads") { let threads = x.parse::().unwrap();