From 819f86537c83ffacbbdce93327f444ac1ddf66a9 Mon Sep 17 00:00:00 2001 From: Chris Hennick <4961925+Pr0methean@users.noreply.github.com> Date: Wed, 15 May 2024 15:31:17 -0700 Subject: [PATCH] refactor: Remove unnecessary #[cfg] attributes --- examples/write-large-file.rs | 46 ++++++++++++++++-------------------- examples/write_dir.rs | 17 ------------- 2 files changed, 20 insertions(+), 43 deletions(-) diff --git a/examples/write-large-file.rs b/examples/write-large-file.rs index d9742e28..f2bb1e52 100644 --- a/examples/write-large-file.rs +++ b/examples/write-large-file.rs @@ -12,32 +12,26 @@ fn main() -> Result<(), Box> { #[cfg(feature = "_deflate-any")] { let filename = &*args[1]; - doit(filename)?; + use std::io::Write; + + use zip::write::SimpleFileOptions; + + let file = std::fs::File::create(filename)?; + let mut zip = zip::ZipWriter::new(file); + + let options = SimpleFileOptions::default() + .compression_method(zip::CompressionMethod::Deflated) + // files over u32::MAX require this flag set. + .large_file(true) + .unix_permissions(0o755); + zip.start_file("huge-file-of-zeroes", options)?; + let content: Vec<_> = std::iter::repeat(0_u8).take(65 * 1024).collect(); + let mut bytes_written = 0_u64; + while bytes_written < u32::MAX as u64 { + zip.write_all(&content)?; + bytes_written += content.len() as u64; + } + zip.finish()?; } Ok(()) } - -#[cfg(feature = "_deflate-any")] -fn doit(filename: &str) -> zip::result::ZipResult<()> { - use std::io::Write; - - use zip::write::SimpleFileOptions; - - let file = std::fs::File::create(filename)?; - let mut zip = zip::ZipWriter::new(file); - - let options = SimpleFileOptions::default() - .compression_method(zip::CompressionMethod::Deflated) - // files over u32::MAX require this flag set. - .large_file(true) - .unix_permissions(0o755); - zip.start_file("huge-file-of-zeroes", options)?; - let content: Vec<_> = std::iter::repeat(0_u8).take(65 * 1024).collect(); - let mut bytes_written = 0_u64; - while bytes_written < u32::MAX as u64 { - zip.write_all(&content)?; - bytes_written += content.len() as u64; - } - zip.finish()?; - Ok(()) -} diff --git a/examples/write_dir.rs b/examples/write_dir.rs index d9cd7342..a34c3bb0 100644 --- a/examples/write_dir.rs +++ b/examples/write_dir.rs @@ -35,23 +35,6 @@ fn main() { std::process::exit(real_main()); } -const METHOD_STORED: Option = Some(zip::CompressionMethod::Stored); - -#[cfg(feature = "_deflate-any")] -const METHOD_DEFLATED: Option = Some(zip::CompressionMethod::Deflated); -#[cfg(not(feature = "_deflate-any"))] -const METHOD_DEFLATED: Option = None; - -#[cfg(feature = "bzip2")] -const METHOD_BZIP2: Option = Some(zip::CompressionMethod::Bzip2); -#[cfg(not(feature = "bzip2"))] -const METHOD_BZIP2: Option = None; - -#[cfg(feature = "zstd")] -const METHOD_ZSTD: Option = Some(zip::CompressionMethod::Zstd); -#[cfg(not(feature = "zstd"))] -const METHOD_ZSTD: Option = None; - fn real_main() -> i32 { let args = Args::parse(); let src_dir = &args.source;