Skip to content

Commit

Permalink
refactor!: remove deflate-miniz feature since it's now equivalent t…
Browse files Browse the repository at this point in the history
…o `deflate` (#35)
  • Loading branch information
Pr0methean committed Apr 24, 2024
1 parent 3aa2406 commit 1663321
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 135 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 2 additions & 13 deletions examples/write_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,9 @@ fn main() {

const METHOD_STORED: Option<zip::CompressionMethod> = Some(zip::CompressionMethod::Stored);

#[cfg(any(
feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib",
feature = "deflate-zlib-ng"
))]
#[cfg(any(feature = "_deflate-any"))]

Check failure on line 15 in examples/write_dir.rs

View workflow job for this annotation

GitHub Actions / clippy

unneeded sub `cfg` when there is only one condition
const METHOD_DEFLATED: Option<zip::CompressionMethod> = 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<zip::CompressionMethod> = None;

#[cfg(feature = "bzip2")]
Expand Down
51 changes: 5 additions & 46 deletions src/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -63,15 +62,13 @@ 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"
))]
pub const DEFLATE: Self = CompressionMethod::Deflated;
#[cfg(not(any(
feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib",
feature = "deflate-zlib-ng",
feature = "deflate-zopfli"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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;
}
}
Expand All @@ -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,
Expand Down
36 changes: 5 additions & 31 deletions src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use std::sync::{Arc, OnceLock};

#[cfg(any(
feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib",
feature = "deflate-zlib-ng"
))]
Expand Down Expand Up @@ -141,12 +140,7 @@ pub(crate) enum ZipFileReader<'a> {
NoReader,
Raw(io::Take<&'a mut dyn Read>),
Stored(Crc32Reader<CryptoReader<'a>>),
#[cfg(any(
feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib",
feature = "deflate-zlib-ng"
))]
#[cfg(feature = "_deflate-any")]
Deflated(Crc32Reader<DeflateDecoder<CryptoReader<'a>>>),
#[cfg(feature = "deflate64")]
Deflate64(Crc32Reader<Deflate64Decoder<io::BufReader<CryptoReader<'a>>>>),
Expand All @@ -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),
Expand All @@ -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(),
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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;
Expand Down
45 changes: 6 additions & 39 deletions src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,7 +20,6 @@ use std::sync::{Arc, OnceLock};

#[cfg(any(
feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib",
feature = "deflate-zlib-ng"
))]
Expand Down Expand Up @@ -73,7 +64,6 @@ enum GenericZipWriter<W: Write + Seek> {
Storer(MaybeEncrypted<W>),
#[cfg(any(
feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib",
feature = "deflate-zlib-ng"
))]
Expand Down Expand Up @@ -1311,20 +1301,15 @@ impl<W: Write + Seek> GenericZipWriter<W> {
}
#[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(
Expand Down Expand Up @@ -1366,7 +1351,6 @@ impl<W: Write + Seek> GenericZipWriter<W> {

#[cfg(any(
feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib",
feature = "deflate-zlib-ng",
))]
Expand Down Expand Up @@ -1432,7 +1416,6 @@ impl<W: Write + Seek> GenericZipWriter<W> {
Storer(w) => w,
#[cfg(any(
feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib",
feature = "deflate-zlib-ng"
))]
Expand Down Expand Up @@ -1462,7 +1445,6 @@ impl<W: Write + Seek> GenericZipWriter<W> {
Storer(ref mut w) => Some(w as &mut dyn Write),
#[cfg(any(
feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib",
feature = "deflate-zlib-ng"
))]
Expand Down Expand Up @@ -1498,16 +1480,9 @@ impl<W: Write + Seek> GenericZipWriter<W> {
}
}

#[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<i64> {
let min = if cfg!(feature = "deflate")
|| cfg!(feature = "deflate-miniz")
|| cfg!(feature = "deflate-zlib")
|| cfg!(feature = "deflate-zlib-ng")
{
Expand All @@ -1533,15 +1508,7 @@ fn bzip2_compression_level_range() -> std::ops::RangeInclusive<i64> {
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<T: Ord + Copy, U: Ord + Copy + TryFrom<T>>(
value: T,
range: std::ops::RangeInclusive<U>,
Expand Down

0 comments on commit 1663321

Please sign in to comment.