diff --git a/src/cli.rs b/src/cli.rs index aab9681a..aa5431b3 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -340,6 +340,17 @@ speed up compression for large files. This option requires '--zopfli' to be set. .value_parser(value_parser!(NonZeroU64)) .requires("zopfli"), ) + .arg( + Arg::new("iterations-without-improvement") + .hide_short_help(true) + .long_help("\ +Stop Zopfli compression after this number of iterations without improvement. Use this in \ +conjunction with a high value for '--zi' to achieve better compression in reasonable time.") + .long("ziwi") + .value_name("iterations") + .value_parser(value_parser!(NonZeroU64)) + .requires("zopfli"), + ) .arg( Arg::new("timeout") .help("Maximum amount of time to spend on optimizations") diff --git a/src/main.rs b/src/main.rs index 9c55b74d..3e68852b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -334,8 +334,12 @@ fn parse_opts_into_struct( #[cfg(feature = "zopfli")] if matches.get_flag("zopfli") { let iteration_count = *matches.get_one::("iterations").unwrap(); + let iterations_without_improvement = *matches + .get_one::("iterations-without-improvement") + .unwrap_or(&NonZeroU64::MAX); opts.deflater = Deflater::Zopfli(ZopfliOptions { iteration_count, + iterations_without_improvement, ..Default::default() }); }