From c05b6c2317c71ee293ff5f75ed1f656464a113b1 Mon Sep 17 00:00:00 2001 From: Mackenzie Clark Date: Sun, 4 Nov 2018 10:12:16 -0800 Subject: [PATCH] add libflate feature --- .gitignore | 2 ++ .travis.yml | 6 +++--- Cargo.toml | 8 +++----- appveyor.yml | 3 ++- examples/write_dir.rs | 12 ++++++------ src/compression.rs | 16 ++++++++-------- src/lib.rs | 4 ++-- src/read.rs | 20 +++++++++----------- src/write.rs | 26 ++++++++++++-------------- 9 files changed, 47 insertions(+), 50 deletions(-) diff --git a/.gitignore b/.gitignore index fa8d85ac..f976c0b5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ Cargo.lock target + +\.idea/ diff --git a/.travis.yml b/.travis.yml index 46bbd08f..a7dfad13 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,9 +16,9 @@ script: [ "$TRAVIS_RUST_VERSION" = "1.20.0" ] || cargo test - cargo test --no-default-features - | - [ "$TRAVIS_RUST_VERSION" = "1.20.0" ] || cargo test --no-default-features --features "deflate-zlib" - - cargo test --no-default-features --features "deflate-miniz" - - cargo doc --no-deps --no-default-features --features "deflate-miniz,bzip2" + [ "$TRAVIS_RUST_VERSION" = "1.20.0" ] || cargo test --no-default-features --features "deflate" + - cargo test --no-default-features --features "deflate" + - cargo doc --no-deps - rustdoc --test README.md -L target/debug after_success: diff --git a/Cargo.toml b/Cargo.toml index 9b32474f..ee9d839a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,17 +12,15 @@ Library to support the reading and writing of zip files. """ [dependencies] -flate2 = { version = "1.0", default-features = false, optional = true } time = "0.1" podio = "0.1" msdos_time = "0.1" bzip2 = { version = "0.3", optional = true } +libflate = { version = "0.1.16", optional = true } [dev-dependencies] walkdir = "1.0" [features] -deflate = ["flate2", "flate2/rust_backend"] -deflate-miniz = ["flate2", "flate2/miniz-sys"] -deflate-zlib = ["flate2", "flate2/zlib"] -default = ["bzip2", "deflate"] +deflate = ["libflate"] +default = ["bzip2", "deflate"] \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index b9450e3c..f5c71017 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -42,4 +42,5 @@ build: false test_script: - cargo test - cargo test --no-default-features - - cargo test --no-default-features --features "deflate-miniz" + - cargo test --no-default-features --features "deflate" + - cargo test --no-default-features --features "bzip2" diff --git a/examples/write_dir.rs b/examples/write_dir.rs index 0e6f59bd..058e9e7f 100644 --- a/examples/write_dir.rs +++ b/examples/write_dir.rs @@ -17,16 +17,16 @@ fn main() { const METHOD_STORED : Option = Some(zip::CompressionMethod::Stored); -#[cfg(feature = "flate2")] -const METHOD_DEFLATED : Option = Some(zip::CompressionMethod::Deflated); -#[cfg(not(feature = "flate2"))] -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 = "deflate")] +const METHOD_DEFLATED : Option = Some(zip::CompressionMethod::Deflated); +#[cfg(not(feature = "deflate"))] +const METHOD_DEFLATED : Option = None; + fn real_main() -> i32 { let args: Vec<_> = std::env::args().collect(); if args.len() < 3 { @@ -37,7 +37,7 @@ fn real_main() -> i32 { let src_dir = &*args[1]; let dst_file = &*args[2]; - for &method in [METHOD_STORED, METHOD_DEFLATED, METHOD_BZIP2].iter() { + for &method in [METHOD_STORED, METHOD_BZIP2, METHOD_DEFLATED].iter() { if method.is_none() { continue } match doit(src_dir, dst_file, method.unwrap()) { Ok(_) => println!("done: {} written to {}", src_dir, dst_file), diff --git a/src/compression.rs b/src/compression.rs index 79c41a8f..cbf73b79 100644 --- a/src/compression.rs +++ b/src/compression.rs @@ -8,8 +8,8 @@ pub enum CompressionMethod { /// The file is stored (no compression) Stored, - /// The file is Deflated - #[cfg(feature = "flate2")] + /// Deflate in pure rust + #[cfg(feature = "deflate")] Deflated, /// File is compressed using BZIP2 algorithm #[cfg(feature = "bzip2")] @@ -23,7 +23,7 @@ impl CompressionMethod { pub fn from_u16(val: u16) -> CompressionMethod { match val { 0 => CompressionMethod::Stored, - #[cfg(feature = "flate2")] + #[cfg(feature = "deflate")] 8 => CompressionMethod::Deflated, #[cfg(feature = "bzip2")] 12 => CompressionMethod::Bzip2, @@ -35,7 +35,7 @@ impl CompressionMethod { pub fn to_u16(self) -> u16 { match self { CompressionMethod::Stored => 0, - #[cfg(feature = "flate2")] + #[cfg(feature = "deflate")] CompressionMethod::Deflated => 8, #[cfg(feature = "bzip2")] CompressionMethod::Bzip2 => 12, @@ -65,22 +65,22 @@ mod test { } } - #[cfg(all(not(feature = "bzip2"), feature = "flate2"))] + #[cfg(all(not(feature = "bzip2"), feature = "deflate"))] fn methods() -> Vec { vec![CompressionMethod::Stored, CompressionMethod::Deflated] } - #[cfg(all(not(feature = "flate2"), feature = "bzip2"))] + #[cfg(all(not(feature = "deflate"), feature = "bzip2"))] fn methods() -> Vec { vec![CompressionMethod::Stored, CompressionMethod::Bzip2] } - #[cfg(all(feature = "bzip2", feature = "flate2"))] + #[cfg(all(feature = "bzip2", feature = "deflate"))] fn methods() -> Vec { vec![CompressionMethod::Stored, CompressionMethod::Deflated, CompressionMethod::Bzip2] } - #[cfg(all(not(feature = "bzip2"), not(feature = "flate2")))] + #[cfg(all(not(feature = "bzip2"), not(feature = "deflate")))] fn methods() -> Vec { vec![CompressionMethod::Stored] } diff --git a/src/lib.rs b/src/lib.rs index f694dfc0..f4d7738a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,8 +4,8 @@ #[cfg(feature = "bzip2")] extern crate bzip2; -#[cfg(feature = "flate2")] -extern crate flate2; +#[cfg(feature = "deflate")] +extern crate libflate; extern crate msdos_time; extern crate podio; extern crate time; diff --git a/src/read.rs b/src/read.rs index de614eb0..64b45783 100644 --- a/src/read.rs +++ b/src/read.rs @@ -14,10 +14,8 @@ use types::{ZipFileData, System}; use cp437::FromCp437; use msdos_time::{TmMsDosExt, MsDosDateTime}; -#[cfg(feature = "flate2")] -use flate2; -#[cfg(feature = "flate2")] -use flate2::read::DeflateDecoder; +#[cfg(feature = "deflate")] +use libflate::deflate::Decoder; #[cfg(feature = "bzip2")] use bzip2::read::BzDecoder; @@ -80,8 +78,8 @@ pub struct ZipArchive enum ZipFileReader<'a> { NoReader, Stored(Crc32Reader>), - #[cfg(feature = "flate2")] - Deflated(Crc32Reader>>), + #[cfg(feature = "deflate")] + Deflated(Crc32Reader>>), #[cfg(feature = "bzip2")] Bzip2(Crc32Reader>>), } @@ -111,10 +109,10 @@ fn make_reader<'a>( reader, crc32))) }, - #[cfg(feature = "flate2")] + #[cfg(feature = "deflate")] CompressionMethod::Deflated => { - let deflate_reader = DeflateDecoder::new(reader); + let deflate_reader = Decoder::new(reader); Ok(ZipFileReader::Deflated(Crc32Reader::new( deflate_reader, crc32))) @@ -440,14 +438,14 @@ fn get_reader<'a>(reader: &'a mut ZipFileReader) -> &'a mut Read { match *reader { ZipFileReader::NoReader => panic!("ZipFileReader was in an invalid state"), ZipFileReader::Stored(ref mut r) => r as &mut Read, - #[cfg(feature = "flate2")] + #[cfg(feature = "deflate")] ZipFileReader::Deflated(ref mut r) => r as &mut Read, #[cfg(feature = "bzip2")] ZipFileReader::Bzip2(ref mut r) => r as &mut Read, } } -/// Methods for retreiving information on zip files +/// Methods for retrieving information on zip files impl<'a> ZipFile<'a> { fn get_reader(&mut self) -> &mut Read { get_reader(&mut self.reader) @@ -544,7 +542,7 @@ impl<'a> Drop for ZipFile<'a> { let mut reader = match innerreader { ZipFileReader::NoReader => panic!("ZipFileReader was in an invalid state"), ZipFileReader::Stored(crcreader) => crcreader.into_inner(), - #[cfg(feature = "flate2")] + #[cfg(feature = "deflate")] ZipFileReader::Deflated(crcreader) => crcreader.into_inner().into_inner(), #[cfg(feature = "bzip2")] ZipFileReader::Bzip2(crcreader) => crcreader.into_inner().into_inner(), diff --git a/src/write.rs b/src/write.rs index d981bd1f..08107f7a 100644 --- a/src/write.rs +++ b/src/write.rs @@ -13,10 +13,8 @@ use time; use podio::{WritePodExt, LittleEndian}; use msdos_time::TmMsDosExt; -#[cfg(feature = "flate2")] -use flate2; -#[cfg(feature = "flate2")] -use flate2::write::DeflateEncoder; +#[cfg(feature = "deflate")] +use libflate; #[cfg(feature = "bzip2")] use bzip2; @@ -29,8 +27,8 @@ enum GenericZipWriter { Closed, Storer(W), - #[cfg(feature = "flate2")] - Deflater(DeflateEncoder), + #[cfg(feature = "deflate")] + Deflater(libflate::deflate::Encoder), #[cfg(feature = "bzip2")] Bzip2(BzEncoder), } @@ -83,7 +81,7 @@ pub struct FileOptions { } impl FileOptions { - #[cfg(feature = "flate2")] + #[cfg(feature = "deflate")] /// Construct a new FileOptions object pub fn default() -> FileOptions { FileOptions { @@ -93,7 +91,7 @@ impl FileOptions { } } - #[cfg(not(feature = "flate2"))] + #[cfg(not(feature = "deflate"))] /// Construct a new FileOptions object pub fn default() -> FileOptions { FileOptions { @@ -358,8 +356,8 @@ impl GenericZipWriter let bare = match mem::replace(self, GenericZipWriter::Closed) { GenericZipWriter::Storer(w) => w, - #[cfg(feature = "flate2")] - GenericZipWriter::Deflater(w) => w.finish()?, + #[cfg(feature = "deflate")] + GenericZipWriter::Deflater(w) => w.finish().into_result()?, #[cfg(feature = "bzip2")] GenericZipWriter::Bzip2(w) => w.finish()?, GenericZipWriter::Closed => Err(io::Error::new(io::ErrorKind::BrokenPipe, "ZipWriter was already closed"))?, @@ -368,8 +366,8 @@ impl GenericZipWriter *self = match compression { CompressionMethod::Stored => GenericZipWriter::Storer(bare), - #[cfg(feature = "flate2")] - CompressionMethod::Deflated => GenericZipWriter::Deflater(DeflateEncoder::new(bare, flate2::Compression::default())), + #[cfg(feature = "deflate")] + CompressionMethod::Deflated => GenericZipWriter::Deflater(libflate::deflate::Encoder::new(bare)), #[cfg(feature = "bzip2")] CompressionMethod::Bzip2 => GenericZipWriter::Bzip2(BzEncoder::new(bare, bzip2::Compression::Default)), CompressionMethod::Unsupported(..) => return Err(ZipError::UnsupportedArchive("Unsupported compression")), @@ -381,7 +379,7 @@ impl GenericZipWriter fn ref_mut(&mut self) -> Option<&mut Write> { match *self { GenericZipWriter::Storer(ref mut w) => Some(w as &mut Write), - #[cfg(feature = "flate2")] + #[cfg(feature = "deflate")] GenericZipWriter::Deflater(ref mut w) => Some(w as &mut Write), #[cfg(feature = "bzip2")] GenericZipWriter::Bzip2(ref mut w) => Some(w as &mut Write), @@ -410,7 +408,7 @@ impl GenericZipWriter fn current_compression(&self) -> Option { match *self { GenericZipWriter::Storer(..) => Some(CompressionMethod::Stored), - #[cfg(feature = "flate2")] + #[cfg(feature = "deflate")] GenericZipWriter::Deflater(..) => Some(CompressionMethod::Deflated), #[cfg(feature = "bzip2")] GenericZipWriter::Bzip2(..) => Some(CompressionMethod::Bzip2),