refactor!: remove deflate-miniz feature since it's now equivalent to deflate (#35)

This commit is contained in:
Chris Hennick 2024-04-24 00:20:34 -07:00
parent 3aa2406c83
commit 1663321323
No known key found for this signature in database
GPG key ID: DA47AABA4961C509
6 changed files with 23 additions and 135 deletions

View file

@ -54,11 +54,11 @@ anyhow = "1"
[features] [features]
aes-crypto = ["aes", "constant_time_eq", "hmac", "pbkdf2", "sha1"] aes-crypto = ["aes", "constant_time_eq", "hmac", "pbkdf2", "sha1"]
chrono = ["chrono/default"] chrono = ["chrono/default"]
deflate = ["flate2/rust_backend"] _deflate-any = []
deflate-miniz = ["flate2/default"] deflate = ["flate2/rust_backend", "_deflate-any"]
deflate-zlib = ["flate2/zlib"] deflate-zlib = ["flate2/zlib", "_deflate-any"]
deflate-zlib-ng = ["flate2/zlib-ng"] deflate-zlib-ng = ["flate2/zlib-ng", "_deflate-any"]
deflate-zopfli = ["zopfli"] deflate-zopfli = ["zopfli", "_deflate-any"]
lzma = ["lzma-rs/stream"] lzma = ["lzma-rs/stream"]
unreserved = [] unreserved = []
default = [ default = [

View file

@ -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. * `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`: 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`: 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). * `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. This is the fastest `deflate` implementation available.

View file

@ -12,20 +12,9 @@ fn main() {
const METHOD_STORED: Option<zip::CompressionMethod> = Some(zip::CompressionMethod::Stored); const METHOD_STORED: Option<zip::CompressionMethod> = Some(zip::CompressionMethod::Stored);
#[cfg(any( #[cfg(any(feature = "_deflate-any"))]
feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib",
feature = "deflate-zlib-ng"
))]
const METHOD_DEFLATED: Option<zip::CompressionMethod> = Some(zip::CompressionMethod::Deflated); const METHOD_DEFLATED: Option<zip::CompressionMethod> = Some(zip::CompressionMethod::Deflated);
#[cfg(not(any( #[cfg(not(feature = "_deflate-any"))]
feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib",
feature = "deflate-zlib-ng",
feature = "deflate-zopfli"
)))]
const METHOD_DEFLATED: Option<zip::CompressionMethod> = None; const METHOD_DEFLATED: Option<zip::CompressionMethod> = None;
#[cfg(feature = "bzip2")] #[cfg(feature = "bzip2")]

View file

@ -19,7 +19,6 @@ pub enum CompressionMethod {
/// Compress the file using Deflate /// Compress the file using Deflate
#[cfg(any( #[cfg(any(
feature = "deflate", feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib", feature = "deflate-zlib",
feature = "deflate-zlib-ng", feature = "deflate-zlib-ng",
feature = "deflate-zopfli" feature = "deflate-zopfli"
@ -63,7 +62,6 @@ impl CompressionMethod {
pub const IMPLODE: Self = CompressionMethod::Unsupported(6); pub const IMPLODE: Self = CompressionMethod::Unsupported(6);
#[cfg(any( #[cfg(any(
feature = "deflate", feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib", feature = "deflate-zlib",
feature = "deflate-zlib-ng", feature = "deflate-zlib-ng",
feature = "deflate-zopfli" feature = "deflate-zopfli"
@ -71,7 +69,6 @@ impl CompressionMethod {
pub const DEFLATE: Self = CompressionMethod::Deflated; pub const DEFLATE: Self = CompressionMethod::Deflated;
#[cfg(not(any( #[cfg(not(any(
feature = "deflate", feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib", feature = "deflate-zlib",
feature = "deflate-zlib-ng", feature = "deflate-zlib-ng",
feature = "deflate-zopfli" feature = "deflate-zopfli"
@ -119,7 +116,6 @@ impl CompressionMethod {
0 => CompressionMethod::Stored, 0 => CompressionMethod::Stored,
#[cfg(any( #[cfg(any(
feature = "deflate", feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib", feature = "deflate-zlib",
feature = "deflate-zlib-ng", feature = "deflate-zlib-ng",
feature = "deflate-zopfli" feature = "deflate-zopfli"
@ -151,7 +147,6 @@ impl CompressionMethod {
CompressionMethod::Stored => 0, CompressionMethod::Stored => 0,
#[cfg(any( #[cfg(any(
feature = "deflate", feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib", feature = "deflate-zlib",
feature = "deflate-zlib-ng", feature = "deflate-zlib-ng",
feature = "deflate-zopfli" feature = "deflate-zopfli"
@ -175,49 +170,19 @@ impl CompressionMethod {
impl Default for CompressionMethod { impl Default for CompressionMethod {
fn default() -> Self { fn default() -> Self {
#[cfg(any( #[cfg(feature = "_deflate-any")]
feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib",
feature = "deflate-zlib-ng",
feature = "deflate-zopfli"
))]
return CompressionMethod::Deflated; return CompressionMethod::Deflated;
#[cfg(all( #[cfg(all(not(any(feature = "_deflate-any")), feature = "bzip2"))]
not(any(
feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib",
feature = "deflate-zlib-ng",
feature = "deflate-zopfli"
)),
feature = "bzip2"
))]
return CompressionMethod::Bzip2; return CompressionMethod::Bzip2;
#[cfg(all( #[cfg(all(
not(any( not(any(feature = "_deflate-any", feature = "bzip2")),
feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib",
feature = "deflate-zlib-ng",
feature = "deflate-zopfli",
feature = "bzip2"
)),
feature = "zstd" feature = "zstd"
))] ))]
return CompressionMethod::Zstd; return CompressionMethod::Zstd;
#[cfg(not(any( #[cfg(not(any(feature = "_deflate-any", feature = "bzip2", feature = "zstd")))]
feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib",
feature = "deflate-zlib-ng",
feature = "deflate-zopfli",
feature = "bzip2",
feature = "zstd"
)))]
return CompressionMethod::Stored; return CompressionMethod::Stored;
} }
} }
@ -232,13 +197,7 @@ impl fmt::Display for CompressionMethod {
/// The compression methods which have been implemented. /// The compression methods which have been implemented.
pub const SUPPORTED_COMPRESSION_METHODS: &[CompressionMethod] = &[ pub const SUPPORTED_COMPRESSION_METHODS: &[CompressionMethod] = &[
CompressionMethod::Stored, CompressionMethod::Stored,
#[cfg(any( #[cfg(feature = "_deflate-any")]
feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib",
feature = "deflate-zlib-ng",
feature = "deflate-zopfli"
))]
CompressionMethod::Deflated, CompressionMethod::Deflated,
#[cfg(feature = "deflate64")] #[cfg(feature = "deflate64")]
CompressionMethod::Deflate64, CompressionMethod::Deflate64,

View file

@ -20,7 +20,6 @@ use std::sync::{Arc, OnceLock};
#[cfg(any( #[cfg(any(
feature = "deflate", feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib", feature = "deflate-zlib",
feature = "deflate-zlib-ng" feature = "deflate-zlib-ng"
))] ))]
@ -141,12 +140,7 @@ pub(crate) enum ZipFileReader<'a> {
NoReader, NoReader,
Raw(io::Take<&'a mut dyn Read>), Raw(io::Take<&'a mut dyn Read>),
Stored(Crc32Reader<CryptoReader<'a>>), Stored(Crc32Reader<CryptoReader<'a>>),
#[cfg(any( #[cfg(feature = "_deflate-any")]
feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib",
feature = "deflate-zlib-ng"
))]
Deflated(Crc32Reader<DeflateDecoder<CryptoReader<'a>>>), Deflated(Crc32Reader<DeflateDecoder<CryptoReader<'a>>>),
#[cfg(feature = "deflate64")] #[cfg(feature = "deflate64")]
Deflate64(Crc32Reader<Deflate64Decoder<io::BufReader<CryptoReader<'a>>>>), Deflate64(Crc32Reader<Deflate64Decoder<io::BufReader<CryptoReader<'a>>>>),
@ -164,12 +158,7 @@ impl<'a> Read for ZipFileReader<'a> {
ZipFileReader::NoReader => panic!("ZipFileReader was in an invalid state"), ZipFileReader::NoReader => panic!("ZipFileReader was in an invalid state"),
ZipFileReader::Raw(r) => r.read(buf), ZipFileReader::Raw(r) => r.read(buf),
ZipFileReader::Stored(r) => r.read(buf), ZipFileReader::Stored(r) => r.read(buf),
#[cfg(any( #[cfg(feature = "_deflate-any")]
feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib",
feature = "deflate-zlib-ng"
))]
ZipFileReader::Deflated(r) => r.read(buf), ZipFileReader::Deflated(r) => r.read(buf),
#[cfg(feature = "deflate64")] #[cfg(feature = "deflate64")]
ZipFileReader::Deflate64(r) => r.read(buf), ZipFileReader::Deflate64(r) => r.read(buf),
@ -190,12 +179,7 @@ impl<'a> ZipFileReader<'a> {
ZipFileReader::NoReader => panic!("ZipFileReader was in an invalid state"), ZipFileReader::NoReader => panic!("ZipFileReader was in an invalid state"),
ZipFileReader::Raw(r) => r, ZipFileReader::Raw(r) => r,
ZipFileReader::Stored(r) => r.into_inner().into_inner(), ZipFileReader::Stored(r) => r.into_inner().into_inner(),
#[cfg(any( #[cfg(feature = "_deflate-any")]
feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib",
feature = "deflate-zlib-ng"
))]
ZipFileReader::Deflated(r) => r.into_inner().into_inner().into_inner(), ZipFileReader::Deflated(r) => r.into_inner().into_inner().into_inner(),
#[cfg(feature = "deflate64")] #[cfg(feature = "deflate64")]
ZipFileReader::Deflate64(r) => r.into_inner().into_inner().into_inner().into_inner(), ZipFileReader::Deflate64(r) => r.into_inner().into_inner().into_inner().into_inner(),
@ -310,12 +294,7 @@ pub(crate) fn make_reader(
CompressionMethod::Stored => { CompressionMethod::Stored => {
ZipFileReader::Stored(Crc32Reader::new(reader, crc32, ae2_encrypted)) ZipFileReader::Stored(Crc32Reader::new(reader, crc32, ae2_encrypted))
} }
#[cfg(any( #[cfg(feature = "_deflate-any")]
feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib",
feature = "deflate-zlib-ng"
))]
CompressionMethod::Deflated => { CompressionMethod::Deflated => {
let deflate_reader = DeflateDecoder::new(reader); let deflate_reader = DeflateDecoder::new(reader);
ZipFileReader::Deflated(Crc32Reader::new(deflate_reader, crc32, ae2_encrypted)) ZipFileReader::Deflated(Crc32Reader::new(deflate_reader, crc32, ae2_encrypted))
@ -1448,12 +1427,7 @@ mod test {
ZipArchive::new(Cursor::new(v)).expect_err("Invalid file"); ZipArchive::new(Cursor::new(v)).expect_err("Invalid file");
} }
#[cfg(any( #[cfg(feature = "_deflate-any")]
feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib",
feature = "deflate-zlib-ng"
))]
#[test] #[test]
fn test_read_with_data_descriptor() { fn test_read_with_data_descriptor() {
use std::io::Read; use std::io::Read;

View file

@ -6,15 +6,7 @@ use crate::result::{ZipError, ZipResult};
use crate::spec; use crate::spec;
use crate::types::{ffi, DateTime, System, ZipFileData, DEFAULT_VERSION}; use crate::types::{ffi, DateTime, System, ZipFileData, DEFAULT_VERSION};
use byteorder::{LittleEndian, WriteBytesExt}; use byteorder::{LittleEndian, WriteBytesExt};
#[cfg(any( #[cfg(any(feature = "_deflate-any", feature = "bzip2", feature = "zstd",))]
feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib",
feature = "deflate-zlib-ng",
feature = "zopfli",
feature = "bzip2",
feature = "zstd",
))]
use core::num::NonZeroU64; use core::num::NonZeroU64;
use crc32fast::Hasher; use crc32fast::Hasher;
use std::collections::HashMap; use std::collections::HashMap;
@ -28,7 +20,6 @@ use std::sync::{Arc, OnceLock};
#[cfg(any( #[cfg(any(
feature = "deflate", feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib", feature = "deflate-zlib",
feature = "deflate-zlib-ng" feature = "deflate-zlib-ng"
))] ))]
@ -73,7 +64,6 @@ enum GenericZipWriter<W: Write + Seek> {
Storer(MaybeEncrypted<W>), Storer(MaybeEncrypted<W>),
#[cfg(any( #[cfg(any(
feature = "deflate", feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib", feature = "deflate-zlib",
feature = "deflate-zlib-ng" feature = "deflate-zlib-ng"
))] ))]
@ -1311,20 +1301,15 @@ impl<W: Write + Seek> GenericZipWriter<W> {
} }
#[cfg(any( #[cfg(any(
feature = "deflate", feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib", feature = "deflate-zlib",
feature = "deflate-zlib-ng", feature = "deflate-zlib-ng",
feature = "deflate-zopfli" feature = "deflate-zopfli"
))] ))]
CompressionMethod::Deflated => { CompressionMethod::Deflated => {
let default = if cfg!(feature = "deflate") let default = if cfg!(feature = "deflate-zopfli") {
|| cfg!(feature = "deflate-miniz")
|| cfg!(feature = "deflate-zlib")
|| cfg!(feature = "deflate-zlib-ng")
{
Compression::default().level() as i64
} else {
24 24
} else {
Compression::default().level() as i64
}; };
let level = clamp_opt( let level = clamp_opt(
@ -1366,7 +1351,6 @@ impl<W: Write + Seek> GenericZipWriter<W> {
#[cfg(any( #[cfg(any(
feature = "deflate", feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib", feature = "deflate-zlib",
feature = "deflate-zlib-ng", feature = "deflate-zlib-ng",
))] ))]
@ -1432,7 +1416,6 @@ impl<W: Write + Seek> GenericZipWriter<W> {
Storer(w) => w, Storer(w) => w,
#[cfg(any( #[cfg(any(
feature = "deflate", feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib", feature = "deflate-zlib",
feature = "deflate-zlib-ng" feature = "deflate-zlib-ng"
))] ))]
@ -1462,7 +1445,6 @@ impl<W: Write + Seek> GenericZipWriter<W> {
Storer(ref mut w) => Some(w as &mut dyn Write), Storer(ref mut w) => Some(w as &mut dyn Write),
#[cfg(any( #[cfg(any(
feature = "deflate", feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib", feature = "deflate-zlib",
feature = "deflate-zlib-ng" feature = "deflate-zlib-ng"
))] ))]
@ -1498,16 +1480,9 @@ impl<W: Write + Seek> GenericZipWriter<W> {
} }
} }
#[cfg(any( #[cfg(feature = "_deflate-any")]
feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib",
feature = "deflate-zlib-ng",
feature = "deflate-zopfli"
))]
fn deflate_compression_level_range() -> std::ops::RangeInclusive<i64> { fn deflate_compression_level_range() -> std::ops::RangeInclusive<i64> {
let min = if cfg!(feature = "deflate") let min = if cfg!(feature = "deflate")
|| cfg!(feature = "deflate-miniz")
|| cfg!(feature = "deflate-zlib") || cfg!(feature = "deflate-zlib")
|| cfg!(feature = "deflate-zlib-ng") || cfg!(feature = "deflate-zlib-ng")
{ {
@ -1533,15 +1508,7 @@ fn bzip2_compression_level_range() -> std::ops::RangeInclusive<i64> {
min..=max min..=max
} }
#[cfg(any( #[cfg(any(feature = "_deflate-any", feature = "bzip2", feature = "zstd"))]
feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib",
feature = "deflate-zlib-ng",
feature = "deflate-zopfli",
feature = "bzip2",
feature = "zstd"
))]
fn clamp_opt<T: Ord + Copy, U: Ord + Copy + TryFrom<T>>( fn clamp_opt<T: Ord + Copy, U: Ord + Copy + TryFrom<T>>(
value: T, value: T,
range: std::ops::RangeInclusive<U>, range: std::ops::RangeInclusive<U>,