diff --git a/Cargo.toml b/Cargo.toml index 19582eb7..b2cb4efb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,11 +54,11 @@ anyhow = "1" [features] aes-crypto = ["aes", "constant_time_eq", "hmac", "pbkdf2", "sha1"] chrono = ["chrono/default"] -deflate = ["flate2/rust_backend"] -deflate-miniz = ["flate2/default"] -deflate-zlib = ["flate2/zlib"] -deflate-zlib-ng = ["flate2/zlib-ng"] -deflate-zopfli = ["zopfli"] +_deflate-any = [] +deflate = ["flate2/rust_backend", "_deflate-any"] +deflate-zlib = ["flate2/zlib", "_deflate-any"] +deflate-zlib-ng = ["flate2/zlib-ng", "_deflate-any"] +deflate-zopfli = ["zopfli", "_deflate-any"] lzma = ["lzma-rs/stream"] unreserved = [] default = [ diff --git a/README.md b/README.md index fa3dea58..cd007b58 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,6 @@ The features available are: * `aes-crypto`: Enables decryption of files which were encrypted with AES. Supports AE-1 and AE-2 methods. * `deflate`: Enables decompressing the deflate compression algorithm, which is the default for zip files. -* `deflate-miniz`: Enables deflating files with the `miniz_oxide` library (used when compression quality is 0..=9). * `deflate-zlib`: Enables deflating files with the `zlib` library (used when compression quality is 0..=9). * `deflate-zlib-ng`: Enables deflating files with the `zlib-ng` library (used when compression quality is 0..=9). This is the fastest `deflate` implementation available. diff --git a/examples/write_dir.rs b/examples/write_dir.rs index 00aa75b1..16284272 100644 --- a/examples/write_dir.rs +++ b/examples/write_dir.rs @@ -12,20 +12,9 @@ fn main() { const METHOD_STORED: Option = Some(zip::CompressionMethod::Stored); -#[cfg(any( - feature = "deflate", - feature = "deflate-miniz", - feature = "deflate-zlib", - feature = "deflate-zlib-ng" -))] +#[cfg(any(feature = "_deflate-any"))] const METHOD_DEFLATED: Option = Some(zip::CompressionMethod::Deflated); -#[cfg(not(any( - feature = "deflate", - feature = "deflate-miniz", - feature = "deflate-zlib", - feature = "deflate-zlib-ng", - feature = "deflate-zopfli" -)))] +#[cfg(not(feature = "_deflate-any"))] const METHOD_DEFLATED: Option = None; #[cfg(feature = "bzip2")] diff --git a/src/compression.rs b/src/compression.rs index 14be540e..3e35636c 100644 --- a/src/compression.rs +++ b/src/compression.rs @@ -19,7 +19,6 @@ pub enum CompressionMethod { /// Compress the file using Deflate #[cfg(any( feature = "deflate", - feature = "deflate-miniz", feature = "deflate-zlib", feature = "deflate-zlib-ng", feature = "deflate-zopfli" @@ -63,7 +62,6 @@ impl CompressionMethod { pub const IMPLODE: Self = CompressionMethod::Unsupported(6); #[cfg(any( feature = "deflate", - feature = "deflate-miniz", feature = "deflate-zlib", feature = "deflate-zlib-ng", feature = "deflate-zopfli" @@ -71,7 +69,6 @@ impl CompressionMethod { pub const DEFLATE: Self = CompressionMethod::Deflated; #[cfg(not(any( feature = "deflate", - feature = "deflate-miniz", feature = "deflate-zlib", feature = "deflate-zlib-ng", feature = "deflate-zopfli" @@ -119,7 +116,6 @@ impl CompressionMethod { 0 => CompressionMethod::Stored, #[cfg(any( feature = "deflate", - feature = "deflate-miniz", feature = "deflate-zlib", feature = "deflate-zlib-ng", feature = "deflate-zopfli" @@ -151,7 +147,6 @@ impl CompressionMethod { CompressionMethod::Stored => 0, #[cfg(any( feature = "deflate", - feature = "deflate-miniz", feature = "deflate-zlib", feature = "deflate-zlib-ng", feature = "deflate-zopfli" @@ -175,49 +170,19 @@ impl CompressionMethod { impl Default for CompressionMethod { fn default() -> Self { - #[cfg(any( - feature = "deflate", - feature = "deflate-miniz", - feature = "deflate-zlib", - feature = "deflate-zlib-ng", - feature = "deflate-zopfli" - ))] + #[cfg(feature = "_deflate-any")] return CompressionMethod::Deflated; - #[cfg(all( - not(any( - feature = "deflate", - feature = "deflate-miniz", - feature = "deflate-zlib", - feature = "deflate-zlib-ng", - feature = "deflate-zopfli" - )), - feature = "bzip2" - ))] + #[cfg(all(not(any(feature = "_deflate-any")), feature = "bzip2"))] return CompressionMethod::Bzip2; #[cfg(all( - not(any( - feature = "deflate", - feature = "deflate-miniz", - feature = "deflate-zlib", - feature = "deflate-zlib-ng", - feature = "deflate-zopfli", - feature = "bzip2" - )), + not(any(feature = "_deflate-any", feature = "bzip2")), feature = "zstd" ))] return CompressionMethod::Zstd; - #[cfg(not(any( - feature = "deflate", - feature = "deflate-miniz", - feature = "deflate-zlib", - feature = "deflate-zlib-ng", - feature = "deflate-zopfli", - feature = "bzip2", - feature = "zstd" - )))] + #[cfg(not(any(feature = "_deflate-any", feature = "bzip2", feature = "zstd")))] return CompressionMethod::Stored; } } @@ -232,13 +197,7 @@ impl fmt::Display for CompressionMethod { /// The compression methods which have been implemented. pub const SUPPORTED_COMPRESSION_METHODS: &[CompressionMethod] = &[ CompressionMethod::Stored, - #[cfg(any( - feature = "deflate", - feature = "deflate-miniz", - feature = "deflate-zlib", - feature = "deflate-zlib-ng", - feature = "deflate-zopfli" - ))] + #[cfg(feature = "_deflate-any")] CompressionMethod::Deflated, #[cfg(feature = "deflate64")] CompressionMethod::Deflate64, diff --git a/src/read.rs b/src/read.rs index 66e776bb..b1cb0300 100644 --- a/src/read.rs +++ b/src/read.rs @@ -20,7 +20,6 @@ use std::sync::{Arc, OnceLock}; #[cfg(any( feature = "deflate", - feature = "deflate-miniz", feature = "deflate-zlib", feature = "deflate-zlib-ng" ))] @@ -141,12 +140,7 @@ pub(crate) enum ZipFileReader<'a> { NoReader, Raw(io::Take<&'a mut dyn Read>), Stored(Crc32Reader>), - #[cfg(any( - feature = "deflate", - feature = "deflate-miniz", - feature = "deflate-zlib", - feature = "deflate-zlib-ng" - ))] + #[cfg(feature = "_deflate-any")] Deflated(Crc32Reader>>), #[cfg(feature = "deflate64")] Deflate64(Crc32Reader>>>), @@ -164,12 +158,7 @@ impl<'a> Read for ZipFileReader<'a> { ZipFileReader::NoReader => panic!("ZipFileReader was in an invalid state"), ZipFileReader::Raw(r) => r.read(buf), ZipFileReader::Stored(r) => r.read(buf), - #[cfg(any( - feature = "deflate", - feature = "deflate-miniz", - feature = "deflate-zlib", - feature = "deflate-zlib-ng" - ))] + #[cfg(feature = "_deflate-any")] ZipFileReader::Deflated(r) => r.read(buf), #[cfg(feature = "deflate64")] ZipFileReader::Deflate64(r) => r.read(buf), @@ -190,12 +179,7 @@ impl<'a> ZipFileReader<'a> { ZipFileReader::NoReader => panic!("ZipFileReader was in an invalid state"), ZipFileReader::Raw(r) => r, ZipFileReader::Stored(r) => r.into_inner().into_inner(), - #[cfg(any( - feature = "deflate", - feature = "deflate-miniz", - feature = "deflate-zlib", - feature = "deflate-zlib-ng" - ))] + #[cfg(feature = "_deflate-any")] ZipFileReader::Deflated(r) => r.into_inner().into_inner().into_inner(), #[cfg(feature = "deflate64")] ZipFileReader::Deflate64(r) => r.into_inner().into_inner().into_inner().into_inner(), @@ -310,12 +294,7 @@ pub(crate) fn make_reader( CompressionMethod::Stored => { ZipFileReader::Stored(Crc32Reader::new(reader, crc32, ae2_encrypted)) } - #[cfg(any( - feature = "deflate", - feature = "deflate-miniz", - feature = "deflate-zlib", - feature = "deflate-zlib-ng" - ))] + #[cfg(feature = "_deflate-any")] CompressionMethod::Deflated => { let deflate_reader = DeflateDecoder::new(reader); ZipFileReader::Deflated(Crc32Reader::new(deflate_reader, crc32, ae2_encrypted)) @@ -1448,12 +1427,7 @@ mod test { ZipArchive::new(Cursor::new(v)).expect_err("Invalid file"); } - #[cfg(any( - feature = "deflate", - feature = "deflate-miniz", - feature = "deflate-zlib", - feature = "deflate-zlib-ng" - ))] + #[cfg(feature = "_deflate-any")] #[test] fn test_read_with_data_descriptor() { use std::io::Read; diff --git a/src/write.rs b/src/write.rs index aaa6b3a5..d9e66e49 100644 --- a/src/write.rs +++ b/src/write.rs @@ -6,15 +6,7 @@ use crate::result::{ZipError, ZipResult}; use crate::spec; use crate::types::{ffi, DateTime, System, ZipFileData, DEFAULT_VERSION}; use byteorder::{LittleEndian, WriteBytesExt}; -#[cfg(any( - feature = "deflate", - feature = "deflate-miniz", - feature = "deflate-zlib", - feature = "deflate-zlib-ng", - feature = "zopfli", - feature = "bzip2", - feature = "zstd", -))] +#[cfg(any(feature = "_deflate-any", feature = "bzip2", feature = "zstd",))] use core::num::NonZeroU64; use crc32fast::Hasher; use std::collections::HashMap; @@ -28,7 +20,6 @@ use std::sync::{Arc, OnceLock}; #[cfg(any( feature = "deflate", - feature = "deflate-miniz", feature = "deflate-zlib", feature = "deflate-zlib-ng" ))] @@ -73,7 +64,6 @@ enum GenericZipWriter { Storer(MaybeEncrypted), #[cfg(any( feature = "deflate", - feature = "deflate-miniz", feature = "deflate-zlib", feature = "deflate-zlib-ng" ))] @@ -1311,20 +1301,15 @@ impl GenericZipWriter { } #[cfg(any( feature = "deflate", - feature = "deflate-miniz", feature = "deflate-zlib", feature = "deflate-zlib-ng", feature = "deflate-zopfli" ))] CompressionMethod::Deflated => { - let default = if cfg!(feature = "deflate") - || cfg!(feature = "deflate-miniz") - || cfg!(feature = "deflate-zlib") - || cfg!(feature = "deflate-zlib-ng") - { - Compression::default().level() as i64 - } else { + let default = if cfg!(feature = "deflate-zopfli") { 24 + } else { + Compression::default().level() as i64 }; let level = clamp_opt( @@ -1366,7 +1351,6 @@ impl GenericZipWriter { #[cfg(any( feature = "deflate", - feature = "deflate-miniz", feature = "deflate-zlib", feature = "deflate-zlib-ng", ))] @@ -1432,7 +1416,6 @@ impl GenericZipWriter { Storer(w) => w, #[cfg(any( feature = "deflate", - feature = "deflate-miniz", feature = "deflate-zlib", feature = "deflate-zlib-ng" ))] @@ -1462,7 +1445,6 @@ impl GenericZipWriter { Storer(ref mut w) => Some(w as &mut dyn Write), #[cfg(any( feature = "deflate", - feature = "deflate-miniz", feature = "deflate-zlib", feature = "deflate-zlib-ng" ))] @@ -1498,16 +1480,9 @@ impl GenericZipWriter { } } -#[cfg(any( - feature = "deflate", - feature = "deflate-miniz", - feature = "deflate-zlib", - feature = "deflate-zlib-ng", - feature = "deflate-zopfli" -))] +#[cfg(feature = "_deflate-any")] fn deflate_compression_level_range() -> std::ops::RangeInclusive { let min = if cfg!(feature = "deflate") - || cfg!(feature = "deflate-miniz") || cfg!(feature = "deflate-zlib") || cfg!(feature = "deflate-zlib-ng") { @@ -1533,15 +1508,7 @@ fn bzip2_compression_level_range() -> std::ops::RangeInclusive { min..=max } -#[cfg(any( - feature = "deflate", - feature = "deflate-miniz", - feature = "deflate-zlib", - feature = "deflate-zlib-ng", - feature = "deflate-zopfli", - feature = "bzip2", - feature = "zstd" -))] +#[cfg(any(feature = "_deflate-any", feature = "bzip2", feature = "zstd"))] fn clamp_opt>( value: T, range: std::ops::RangeInclusive,