Skip to content

Commit 4876b0b

Browse files
Add option for Zopfli iteration count
1 parent 61deab3 commit 4876b0b

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/cli.rs

+11
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,17 @@ Recommended use is with '-o max' and '--fast'.")
337337
.long("zopfli")
338338
.action(ArgAction::SetTrue),
339339
)
340+
.arg(
341+
Arg::new("iterations")
342+
.help("Number of Zopfli iterations [default: 15]")
343+
.long_help("\
344+
Set the number of iterations to use for Zopfli compression. The default number of \
345+
iterations is 15. Using fewer iterations may speed up compression for large files. This \
346+
option requires '--zopfli' to be set.")
347+
.long("zi")
348+
.value_parser(1..=255)
349+
.requires("zopfli"),
350+
)
340351
.arg(
341352
Arg::new("timeout")
342353
.help("Maximum amount of time to spend on optimizations")

src/main.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -324,12 +324,14 @@ fn parse_opts_into_struct(
324324
opts.strip = StripChunks::Safe;
325325
}
326326

327+
#[cfg(feature = "zopfli")]
327328
if matches.get_flag("zopfli") {
328-
#[cfg(feature = "zopfli")]
329-
if let Some(iterations) = NonZeroU8::new(15) {
330-
opts.deflate = Deflaters::Zopfli { iterations };
331-
}
332-
} else if let (Deflaters::Libdeflater { compression }, Some(x)) =
329+
let iterations = *matches.get_one::<i64>("iterations").unwrap_or(&15);
330+
opts.deflate = Deflaters::Zopfli {
331+
iterations: NonZeroU8::new(iterations as u8).unwrap(),
332+
};
333+
}
334+
if let (Deflaters::Libdeflater { compression }, Some(x)) =
333335
(&mut opts.deflate, matches.get_one::<i64>("compression"))
334336
{
335337
*compression = *x as u8;

0 commit comments

Comments
 (0)