From 3161de632e8b3d4aac4184240e5b2e7db41ef966 Mon Sep 17 00:00:00 2001 From: Chris Hennick Date: Sat, 27 May 2023 14:06:33 -0700 Subject: [PATCH] Rewrite with new functional-update syntax --- src/write.rs | 59 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/src/write.rs b/src/write.rs index 13ef3811..8b2c5981 100644 --- a/src/write.rs +++ b/src/write.rs @@ -1121,18 +1121,19 @@ impl GenericZipWriter { ))] CompressionMethod::Deflated => { #[cfg(all( - not(feature = "deflate"), - not(feature = "deflate-miniz"), - not(feature = "deflate-zlib"), - feature = "deflate-zopfli" + not(feature = "deflate"), + not(feature = "deflate-miniz"), + not(feature = "deflate-zlib"), + feature = "deflate-zopfli" ))] let default = 24; #[cfg(any( - feature = "deflate", - feature = "deflate-miniz", - feature = "deflate-zlib"))] - let default = flate2::Compression::default().level() as i32; + feature = "deflate", + feature = "deflate-miniz", + feature = "deflate-zlib" + ))] + let default = Compression::default().level() as i32; let level = clamp_opt( compression_level.unwrap_or(default), @@ -1151,41 +1152,49 @@ impl GenericZipWriter { })); #[cfg(all( - not(feature = "deflate"), - not(feature = "deflate-miniz"), - not(feature = "deflate-zlib"), - feature = "deflate-zopfli" + not(feature = "deflate"), + not(feature = "deflate-miniz"), + not(feature = "deflate-zlib"), + feature = "deflate-zopfli" ))] return Ok(Box::new(move |bare| { let mut options = Options::default(); - options.iteration_count = NonZeroU8::try_from((level - best_non_zopfli) as u8).unwrap(); + options.iteration_count = + NonZeroU8::try_from((level - best_non_zopfli) as u8).unwrap(); GenericZipWriter::ZopfliDeflater(zopfli::DeflateEncoder::new( options, Default::default(), - bare + bare, )) })); #[cfg(all( - any(feature = "deflate", - feature = "deflate-miniz", - feature = "deflate-zlib"), - feature = "deflate-zopfli") - )] + any( + feature = "deflate", + feature = "deflate-miniz", + feature = "deflate-zlib" + ), + feature = "deflate-zopfli" + ))] Ok(Box::new(move |bare| { let best_non_zopfli = Compression::best().level(); if level > best_non_zopfli { - let mut options = Options::default(); - options.iteration_count = NonZeroU8::try_from((level - best_non_zopfli) as u8).unwrap(); + let options = Options { + iteration_count: NonZeroU8::try_from( + (level - best_non_zopfli) as u8, + ) + .unwrap(), + ..Default::default() + }; GenericZipWriter::ZopfliDeflater(zopfli::DeflateEncoder::new( options, Default::default(), - bare + bare, )) } else { GenericZipWriter::Deflater(DeflateEncoder::new( bare, - flate2::Compression::new(level), + Compression::new(level), )) } })) @@ -1306,7 +1315,7 @@ fn deflate_compression_level_range() -> std::ops::RangeInclusive { feature = "deflate-miniz", feature = "deflate-zlib", ))] - let min = flate2::Compression::none().level() as i32; + let min = Compression::none().level() as i32; #[cfg(not(any( feature = "deflate", @@ -1319,7 +1328,7 @@ fn deflate_compression_level_range() -> std::ops::RangeInclusive { let max = flate2::Compression::best().level() as i32; #[cfg(feature = "deflate-zopfli")] - let max = flate2::Compression::best().level() as i32 + u8::MAX as i32; + let max = Compression::best().level() as i32 + u8::MAX as i32; min..=max }