From 6f9150d3dc82d8e8a3e2ce31f8d0f633710f7f25 Mon Sep 17 00:00:00 2001 From: jonpas Date: Fri, 14 Jun 2019 15:02:41 +0200 Subject: [PATCH 1/5] Fix compilation error --- src/cp437.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cp437.rs b/src/cp437.rs index 69547219..751d5b1b 100644 --- a/src/cp437.rs +++ b/src/cp437.rs @@ -170,6 +170,7 @@ fn to_char(input: u8) -> char 0xfd => 0x00b2, 0xfe => 0x25a0, 0xff => 0x00a0, + _ => 0x0 }; ::std::char::from_u32(output).unwrap() } From b171b915f820c139ce369b5ae30f41eb8519cd38 Mon Sep 17 00:00:00 2001 From: jonpas Date: Fri, 14 Jun 2019 15:25:00 +0200 Subject: [PATCH 2/5] Switch to flate2 --- Cargo.toml | 6 ++++-- examples/write_dir.rs | 4 ++-- src/compression.rs | 6 +++--- src/lib.rs | 4 ++-- src/read.rs | 18 ++++++++++-------- src/write.rs | 26 ++++++++++++++------------ 6 files changed, 35 insertions(+), 29 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b11e0ae4..13adebf9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,10 +12,10 @@ Library to support the reading and writing of zip files. """ [dependencies] +flate2 = { version = "1.0", default-features = false, optional = true } time = { version = "0.1", optional = true } podio = "0.1" bzip2 = { version = "0.3", optional = true } -libflate = { version = ">=0.1.21", optional = true } crc32fast = "1.0" [dev-dependencies] @@ -24,7 +24,9 @@ rand = "0.4" walkdir = "1.0" [features] -deflate = ["libflate"] +deflate = ["flate2", "flate2/default"] +deflate-zlib = ["flate2", "flate2/zlib"] +deflate-rust = ["flate2", "flate2/rust_backend"] default = ["bzip2", "deflate", "time"] [[bench]] diff --git a/examples/write_dir.rs b/examples/write_dir.rs index fb36ccaf..fef98a7b 100644 --- a/examples/write_dir.rs +++ b/examples/write_dir.rs @@ -17,9 +17,9 @@ fn main() { const METHOD_STORED : Option = Some(zip::CompressionMethod::Stored); -#[cfg(feature = "deflate")] +#[cfg(feature = "flate2")] const METHOD_DEFLATED : Option = Some(zip::CompressionMethod::Deflated); -#[cfg(not(feature = "deflate"))] +#[cfg(not(feature = "flate2"))] const METHOD_DEFLATED : Option = None; #[cfg(feature = "bzip2")] diff --git a/src/compression.rs b/src/compression.rs index 9585ef3b..03a0d595 100644 --- a/src/compression.rs +++ b/src/compression.rs @@ -9,7 +9,7 @@ pub enum CompressionMethod /// The file is stored (no compression) Stored, /// Deflate in pure rust - #[cfg(feature = "deflate")] + #[cfg(feature = "flate2")] 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 = "deflate")] + #[cfg(feature = "flate2")] 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 = "deflate")] + #[cfg(feature = "flate2")] CompressionMethod::Deflated => 8, #[cfg(feature = "bzip2")] CompressionMethod::Bzip2 => 12, diff --git a/src/lib.rs b/src/lib.rs index ef2fd049..5bd7243d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,8 +5,8 @@ #[cfg(feature = "bzip2")] extern crate bzip2; extern crate crc32fast; -#[cfg(feature = "deflate")] -extern crate libflate; +#[cfg(feature = "flate2")] +extern crate flate2; extern crate podio; #[cfg(feature = "time")] extern crate time; diff --git a/src/read.rs b/src/read.rs index e01e1edc..f8404ddf 100644 --- a/src/read.rs +++ b/src/read.rs @@ -13,8 +13,10 @@ use podio::{ReadPodExt, LittleEndian}; use types::{ZipFileData, System, DateTime}; use cp437::FromCp437; -#[cfg(feature = "deflate")] -use libflate; +#[cfg(feature = "flate2")] +use flate2; +#[cfg(feature = "flate2")] +use flate2::read::DeflateDecoder; #[cfg(feature = "bzip2")] use bzip2::read::BzDecoder; @@ -63,8 +65,8 @@ pub struct ZipArchive enum ZipFileReader<'a> { NoReader, Stored(Crc32Reader>), - #[cfg(feature = "deflate")] - Deflated(Crc32Reader>>), + #[cfg(feature = "flate2")] + Deflated(Crc32Reader>>), #[cfg(feature = "bzip2")] Bzip2(Crc32Reader>>), } @@ -94,10 +96,10 @@ fn make_reader<'a>( reader, crc32))) }, - #[cfg(feature = "deflate")] + #[cfg(feature = "flate2")] CompressionMethod::Deflated => { - let deflate_reader = libflate::deflate::Decoder::new(reader); + let deflate_reader = DeflateDecoder::new(reader); Ok(ZipFileReader::Deflated(Crc32Reader::new( deflate_reader, crc32))) @@ -416,7 +418,7 @@ 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 = "deflate")] + #[cfg(feature = "flate2")] ZipFileReader::Deflated(ref mut r) => r as &mut Read, #[cfg(feature = "bzip2")] ZipFileReader::Bzip2(ref mut r) => r as &mut Read, @@ -528,7 +530,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 = "deflate")] + #[cfg(feature = "flate2")] 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 0bba9591..df290456 100644 --- a/src/write.rs +++ b/src/write.rs @@ -13,8 +13,10 @@ use std::mem; use time; use podio::{WritePodExt, LittleEndian}; -#[cfg(feature = "deflate")] -use libflate; +#[cfg(feature = "flate2")] +use flate2; +#[cfg(feature = "flate2")] +use flate2::write::DeflateEncoder; #[cfg(feature = "bzip2")] use bzip2; @@ -25,8 +27,8 @@ enum GenericZipWriter { Closed, Storer(W), - #[cfg(feature = "deflate")] - Deflater(libflate::deflate::Encoder), + #[cfg(feature = "flate2")] + Deflater(DeflateEncoder), #[cfg(feature = "bzip2")] Bzip2(BzEncoder), } @@ -83,8 +85,8 @@ impl FileOptions { /// Construct a new FileOptions object pub fn default() -> FileOptions { FileOptions { - #[cfg(feature = "deflate")] compression_method: CompressionMethod::Deflated, - #[cfg(not(feature = "deflate"))] compression_method: CompressionMethod::Stored, + #[cfg(feature = "flate2")] compression_method: CompressionMethod::Deflated, + #[cfg(not(feature = "flate2"))] compression_method: CompressionMethod::Stored, #[cfg(feature = "time")] last_modified_time: DateTime::from_time(time::now()).unwrap_or(DateTime::default()), #[cfg(not(feature = "time"))] last_modified_time: DateTime::default(), permissions: None, @@ -367,8 +369,8 @@ impl GenericZipWriter let bare = match mem::replace(self, GenericZipWriter::Closed) { GenericZipWriter::Storer(w) => w, - #[cfg(feature = "deflate")] - GenericZipWriter::Deflater(w) => w.finish().into_result()?, + #[cfg(feature = "flate2")] + GenericZipWriter::Deflater(w) => w.finish()?, #[cfg(feature = "bzip2")] GenericZipWriter::Bzip2(w) => w.finish()?, GenericZipWriter::Closed => Err(io::Error::new(io::ErrorKind::BrokenPipe, "ZipWriter was already closed"))?, @@ -377,8 +379,8 @@ impl GenericZipWriter *self = match compression { CompressionMethod::Stored => GenericZipWriter::Storer(bare), - #[cfg(feature = "deflate")] - CompressionMethod::Deflated => GenericZipWriter::Deflater(libflate::deflate::Encoder::new(bare)), + #[cfg(feature = "flate2")] + CompressionMethod::Deflated => GenericZipWriter::Deflater(DeflateEncoder::new(bare, flate2::Compression::default())), #[cfg(feature = "bzip2")] CompressionMethod::Bzip2 => GenericZipWriter::Bzip2(BzEncoder::new(bare, bzip2::Compression::Default)), CompressionMethod::Unsupported(..) => return Err(ZipError::UnsupportedArchive("Unsupported compression")), @@ -390,7 +392,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 = "deflate")] + #[cfg(feature = "flate2")] GenericZipWriter::Deflater(ref mut w) => Some(w as &mut Write), #[cfg(feature = "bzip2")] GenericZipWriter::Bzip2(ref mut w) => Some(w as &mut Write), @@ -419,7 +421,7 @@ impl GenericZipWriter fn current_compression(&self) -> Option { match *self { GenericZipWriter::Storer(..) => Some(CompressionMethod::Stored), - #[cfg(feature = "deflate")] + #[cfg(feature = "flate2")] GenericZipWriter::Deflater(..) => Some(CompressionMethod::Deflated), #[cfg(feature = "bzip2")] GenericZipWriter::Bzip2(..) => Some(CompressionMethod::Bzip2), From 14f77b390a1c0bffb9a6f48abf1b5eb60506d6b1 Mon Sep 17 00:00:00 2001 From: jonpas Date: Mon, 17 Jun 2019 21:36:38 +0200 Subject: [PATCH 3/5] Use deflate as feature name --- Cargo.toml | 6 +++--- examples/write_dir.rs | 4 ++-- src/compression.rs | 6 +++--- src/lib.rs | 2 +- src/read.rs | 12 ++++++------ src/write.rs | 18 +++++++++--------- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 13adebf9..18e174e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,9 +24,9 @@ rand = "0.4" walkdir = "1.0" [features] -deflate = ["flate2", "flate2/default"] -deflate-zlib = ["flate2", "flate2/zlib"] -deflate-rust = ["flate2", "flate2/rust_backend"] +deflate = ["flate2/default"] +deflate-zlib = ["flate2/zlib"] +deflate-rust = ["flate2/rust_backend"] default = ["bzip2", "deflate", "time"] [[bench]] diff --git a/examples/write_dir.rs b/examples/write_dir.rs index fef98a7b..fb36ccaf 100644 --- a/examples/write_dir.rs +++ b/examples/write_dir.rs @@ -17,9 +17,9 @@ fn main() { const METHOD_STORED : Option = Some(zip::CompressionMethod::Stored); -#[cfg(feature = "flate2")] +#[cfg(feature = "deflate")] const METHOD_DEFLATED : Option = Some(zip::CompressionMethod::Deflated); -#[cfg(not(feature = "flate2"))] +#[cfg(not(feature = "deflate"))] const METHOD_DEFLATED : Option = None; #[cfg(feature = "bzip2")] diff --git a/src/compression.rs b/src/compression.rs index 03a0d595..9585ef3b 100644 --- a/src/compression.rs +++ b/src/compression.rs @@ -9,7 +9,7 @@ pub enum CompressionMethod /// The file is stored (no compression) Stored, /// Deflate in pure rust - #[cfg(feature = "flate2")] + #[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, diff --git a/src/lib.rs b/src/lib.rs index 5bd7243d..cfe4a598 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,7 +5,7 @@ #[cfg(feature = "bzip2")] extern crate bzip2; extern crate crc32fast; -#[cfg(feature = "flate2")] +#[cfg(feature = "deflate")] extern crate flate2; extern crate podio; #[cfg(feature = "time")] diff --git a/src/read.rs b/src/read.rs index f8404ddf..2eb3d83b 100644 --- a/src/read.rs +++ b/src/read.rs @@ -13,9 +13,9 @@ use podio::{ReadPodExt, LittleEndian}; use types::{ZipFileData, System, DateTime}; use cp437::FromCp437; -#[cfg(feature = "flate2")] +#[cfg(feature = "deflate")] use flate2; -#[cfg(feature = "flate2")] +#[cfg(feature = "deflate")] use flate2::read::DeflateDecoder; #[cfg(feature = "bzip2")] @@ -65,7 +65,7 @@ pub struct ZipArchive enum ZipFileReader<'a> { NoReader, Stored(Crc32Reader>), - #[cfg(feature = "flate2")] + #[cfg(feature = "deflate")] Deflated(Crc32Reader>>), #[cfg(feature = "bzip2")] Bzip2(Crc32Reader>>), @@ -96,7 +96,7 @@ fn make_reader<'a>( reader, crc32))) }, - #[cfg(feature = "flate2")] + #[cfg(feature = "deflate")] CompressionMethod::Deflated => { let deflate_reader = DeflateDecoder::new(reader); @@ -418,7 +418,7 @@ 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, @@ -530,7 +530,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 df290456..04ddaa95 100644 --- a/src/write.rs +++ b/src/write.rs @@ -13,9 +13,9 @@ use std::mem; use time; use podio::{WritePodExt, LittleEndian}; -#[cfg(feature = "flate2")] +#[cfg(feature = "deflate")] use flate2; -#[cfg(feature = "flate2")] +#[cfg(feature = "deflate")] use flate2::write::DeflateEncoder; #[cfg(feature = "bzip2")] @@ -27,7 +27,7 @@ enum GenericZipWriter { Closed, Storer(W), - #[cfg(feature = "flate2")] + #[cfg(feature = "deflate")] Deflater(DeflateEncoder), #[cfg(feature = "bzip2")] Bzip2(BzEncoder), @@ -85,8 +85,8 @@ impl FileOptions { /// Construct a new FileOptions object pub fn default() -> FileOptions { FileOptions { - #[cfg(feature = "flate2")] compression_method: CompressionMethod::Deflated, - #[cfg(not(feature = "flate2"))] compression_method: CompressionMethod::Stored, + #[cfg(feature = "deflate")] compression_method: CompressionMethod::Deflated, + #[cfg(not(feature = "deflate"))] compression_method: CompressionMethod::Stored, #[cfg(feature = "time")] last_modified_time: DateTime::from_time(time::now()).unwrap_or(DateTime::default()), #[cfg(not(feature = "time"))] last_modified_time: DateTime::default(), permissions: None, @@ -369,7 +369,7 @@ impl GenericZipWriter let bare = match mem::replace(self, GenericZipWriter::Closed) { GenericZipWriter::Storer(w) => w, - #[cfg(feature = "flate2")] + #[cfg(feature = "deflate")] GenericZipWriter::Deflater(w) => w.finish()?, #[cfg(feature = "bzip2")] GenericZipWriter::Bzip2(w) => w.finish()?, @@ -379,7 +379,7 @@ impl GenericZipWriter *self = match compression { CompressionMethod::Stored => GenericZipWriter::Storer(bare), - #[cfg(feature = "flate2")] + #[cfg(feature = "deflate")] CompressionMethod::Deflated => GenericZipWriter::Deflater(DeflateEncoder::new(bare, flate2::Compression::default())), #[cfg(feature = "bzip2")] CompressionMethod::Bzip2 => GenericZipWriter::Bzip2(BzEncoder::new(bare, bzip2::Compression::Default)), @@ -392,7 +392,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), @@ -421,7 +421,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), From c30d7c3d10b39634125d637da24b4be5d32f465f Mon Sep 17 00:00:00 2001 From: jonpas Date: Tue, 18 Jun 2019 12:32:44 +0200 Subject: [PATCH 4/5] Remove _ - updated rustc --- src/cp437.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cp437.rs b/src/cp437.rs index 751d5b1b..69547219 100644 --- a/src/cp437.rs +++ b/src/cp437.rs @@ -170,7 +170,6 @@ fn to_char(input: u8) -> char 0xfd => 0x00b2, 0xfe => 0x25a0, 0xff => 0x00a0, - _ => 0x0 }; ::std::char::from_u32(output).unwrap() } From c82a635c5c5d09321a26284193175878f0a50da2 Mon Sep 17 00:00:00 2001 From: jonpas Date: Thu, 20 Jun 2019 16:29:16 +0200 Subject: [PATCH 5/5] Default deflate to flate2/rust_backend (miniz_oxide) --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 18e174e1..c6bd89cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,9 +24,9 @@ rand = "0.4" walkdir = "1.0" [features] -deflate = ["flate2/default"] +deflate = ["flate2/rust_backend"] +deflate-miniz = ["flate2/default"] deflate-zlib = ["flate2/zlib"] -deflate-rust = ["flate2/rust_backend"] default = ["bzip2", "deflate", "time"] [[bench]]