fix: Use deflate-flate2 flag to guard import

This commit is contained in:
Chris Hennick 2024-06-02 17:29:49 -07:00
parent 79fc5a9cdd
commit 2a131e67a9
No known key found for this signature in database
GPG key ID: DA47AABA4961C509
3 changed files with 8 additions and 28 deletions

View file

@ -42,12 +42,12 @@ fn real_main() -> i32 {
let method = match args.compression_method { let method = match args.compression_method {
CompressionMethod::Stored => zip::CompressionMethod::Stored, CompressionMethod::Stored => zip::CompressionMethod::Stored,
CompressionMethod::Deflated => { CompressionMethod::Deflated => {
#[cfg(not(feature = "deflate"))] #[cfg(not(feature = "deflate-flate2"))]
{ {
println!("The `deflate` feature is not enabled"); println!("The `deflate-flate2` feature is not enabled");
return 1; return 1;
} }
#[cfg(feature = "deflate")] #[cfg(feature = "deflate-flate2")]
zip::CompressionMethod::Deflated zip::CompressionMethod::Deflated
} }
CompressionMethod::DeflatedZlib => { CompressionMethod::DeflatedZlib => {

View file

@ -24,11 +24,7 @@ use std::ops::Deref;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::sync::{Arc, OnceLock}; use std::sync::{Arc, OnceLock};
#[cfg(any( #[cfg(feature = "deflate-flate2")]
feature = "deflate",
feature = "deflate-zlib",
feature = "deflate-zlib-ng"
))]
use flate2::read::DeflateDecoder; use flate2::read::DeflateDecoder;
#[cfg(feature = "deflate64")] #[cfg(feature = "deflate64")]

View file

@ -27,11 +27,7 @@ use std::mem;
use std::str::{from_utf8, Utf8Error}; use std::str::{from_utf8, Utf8Error};
use std::sync::Arc; use std::sync::Arc;
#[cfg(any( #[cfg(feature = "deflate-flate2")]
feature = "deflate",
feature = "deflate-zlib",
feature = "deflate-zlib-ng"
))]
use flate2::{write::DeflateEncoder, Compression}; use flate2::{write::DeflateEncoder, Compression};
#[cfg(feature = "bzip2")] #[cfg(feature = "bzip2")]
@ -1569,11 +1565,7 @@ impl<W: Write + Seek> GenericZipWriter<W> {
} }
} }
#[cfg(any( #[cfg(feature = "deflate-flate2")]
feature = "deflate",
feature = "deflate-zlib",
feature = "deflate-zlib-ng",
))]
{ {
Ok(Box::new(move |bare| { Ok(Box::new(move |bare| {
GenericZipWriter::Deflater(DeflateEncoder::new( GenericZipWriter::Deflater(DeflateEncoder::new(
@ -1633,11 +1625,7 @@ impl<W: Write + Seek> GenericZipWriter<W> {
fn switch_to(&mut self, make_new_self: SwitchWriterFunction<W>) -> ZipResult<()> { fn switch_to(&mut self, make_new_self: SwitchWriterFunction<W>) -> ZipResult<()> {
let bare = match mem::replace(self, Closed) { let bare = match mem::replace(self, Closed) {
Storer(w) => w, Storer(w) => w,
#[cfg(any( #[cfg(feature = "deflate-flate2")]
feature = "deflate",
feature = "deflate-zlib",
feature = "deflate-zlib-ng"
))]
GenericZipWriter::Deflater(w) => w.finish()?, GenericZipWriter::Deflater(w) => w.finish()?,
#[cfg(feature = "deflate-zopfli")] #[cfg(feature = "deflate-zopfli")]
GenericZipWriter::ZopfliDeflater(w) => w.finish()?, GenericZipWriter::ZopfliDeflater(w) => w.finish()?,
@ -1665,11 +1653,7 @@ impl<W: Write + Seek> GenericZipWriter<W> {
fn ref_mut(&mut self) -> Option<&mut dyn Write> { fn ref_mut(&mut self) -> Option<&mut dyn Write> {
match self { match self {
Storer(ref mut w) => Some(w as &mut dyn Write), Storer(ref mut w) => Some(w as &mut dyn Write),
#[cfg(any( #[cfg(feature = "deflate-flate2")]
feature = "deflate",
feature = "deflate-zlib",
feature = "deflate-zlib-ng"
))]
GenericZipWriter::Deflater(ref mut w) => Some(w as &mut dyn Write), GenericZipWriter::Deflater(ref mut w) => Some(w as &mut dyn Write),
#[cfg(feature = "deflate-zopfli")] #[cfg(feature = "deflate-zopfli")]
GenericZipWriter::ZopfliDeflater(w) => Some(w as &mut dyn Write), GenericZipWriter::ZopfliDeflater(w) => Some(w as &mut dyn Write),