refactor!: remove deflate-miniz
feature since it's now equivalent to deflate
(#35)
This commit is contained in:
parent
3aa2406c83
commit
1663321323
6 changed files with 23 additions and 135 deletions
10
Cargo.toml
10
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 = [
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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"))]
|
||||
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")]
|
||||
|
|
|
@ -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,
|
||||
|
|
36
src/read.rs
36
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<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>>>>),
|
||||
|
@ -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;
|
||||
|
|
45
src/write.rs
45
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<W: Write + Seek> {
|
|||
Storer(MaybeEncrypted<W>),
|
||||
#[cfg(any(
|
||||
feature = "deflate",
|
||||
feature = "deflate-miniz",
|
||||
feature = "deflate-zlib",
|
||||
feature = "deflate-zlib-ng"
|
||||
))]
|
||||
|
@ -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(
|
||||
|
@ -1366,7 +1351,6 @@ impl<W: Write + Seek> GenericZipWriter<W> {
|
|||
|
||||
#[cfg(any(
|
||||
feature = "deflate",
|
||||
feature = "deflate-miniz",
|
||||
feature = "deflate-zlib",
|
||||
feature = "deflate-zlib-ng",
|
||||
))]
|
||||
|
@ -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"
|
||||
))]
|
||||
|
@ -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"
|
||||
))]
|
||||
|
@ -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")
|
||||
{
|
||||
|
@ -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>,
|
||||
|
|
Loading…
Add table
Reference in a new issue