Skip to content

Commit

Permalink
Add option for Zopfli iteration count
Browse files Browse the repository at this point in the history
  • Loading branch information
LegionMammal978 authored and AlexTMjugador committed Aug 7, 2024
1 parent 1bb7109 commit dab67ca
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
11 changes: 11 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,17 @@ Recommended use is with '-o max' and '--fast'.")
.long("zopfli")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("iterations")
.help("Number of Zopfli iterations")
.long_help("\
Set the number of iterations to use for Zopfli compression. Using fewer iterations may \
speed up compression for large files. This option requires '--zopfli' to be set.")
.long("zi")
.default_value("15")
.value_parser(1..=255)
.requires("zopfli"),
)
.arg(
Arg::new("timeout")
.help("Maximum amount of time to spend on optimizations")
Expand Down
12 changes: 7 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,14 @@ fn parse_opts_into_struct(
opts.strip = StripChunks::Safe;
}

#[cfg(feature = "zopfli")]
if matches.get_flag("zopfli") {
#[cfg(feature = "zopfli")]
if let Some(iterations) = NonZeroU8::new(15) {
opts.deflate = Deflaters::Zopfli { iterations };
}
} else if let (Deflaters::Libdeflater { compression }, Some(x)) =
let iterations = *matches.get_one::<i64>("iterations").unwrap();
opts.deflate = Deflaters::Zopfli {
iterations: NonZeroU8::new(iterations as u8).unwrap(),
};
}
if let (Deflaters::Libdeflater { compression }, Some(x)) =
(&mut opts.deflate, matches.get_one::<i64>("compression"))
{
*compression = *x as u8;
Expand Down

0 comments on commit dab67ca

Please sign in to comment.