Switch to flate2
This commit is contained in:
parent
6f9150d3dc
commit
b171b915f8
6 changed files with 35 additions and 29 deletions
|
@ -12,10 +12,10 @@ Library to support the reading and writing of zip files.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
flate2 = { version = "1.0", default-features = false, optional = true }
|
||||||
time = { version = "0.1", optional = true }
|
time = { version = "0.1", optional = true }
|
||||||
podio = "0.1"
|
podio = "0.1"
|
||||||
bzip2 = { version = "0.3", optional = true }
|
bzip2 = { version = "0.3", optional = true }
|
||||||
libflate = { version = ">=0.1.21", optional = true }
|
|
||||||
crc32fast = "1.0"
|
crc32fast = "1.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
@ -24,7 +24,9 @@ rand = "0.4"
|
||||||
walkdir = "1.0"
|
walkdir = "1.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
deflate = ["libflate"]
|
deflate = ["flate2", "flate2/default"]
|
||||||
|
deflate-zlib = ["flate2", "flate2/zlib"]
|
||||||
|
deflate-rust = ["flate2", "flate2/rust_backend"]
|
||||||
default = ["bzip2", "deflate", "time"]
|
default = ["bzip2", "deflate", "time"]
|
||||||
|
|
||||||
[[bench]]
|
[[bench]]
|
||||||
|
|
|
@ -17,9 +17,9 @@ fn main() {
|
||||||
|
|
||||||
const METHOD_STORED : Option<zip::CompressionMethod> = Some(zip::CompressionMethod::Stored);
|
const METHOD_STORED : Option<zip::CompressionMethod> = Some(zip::CompressionMethod::Stored);
|
||||||
|
|
||||||
#[cfg(feature = "deflate")]
|
#[cfg(feature = "flate2")]
|
||||||
const METHOD_DEFLATED : Option<zip::CompressionMethod> = Some(zip::CompressionMethod::Deflated);
|
const METHOD_DEFLATED : Option<zip::CompressionMethod> = Some(zip::CompressionMethod::Deflated);
|
||||||
#[cfg(not(feature = "deflate"))]
|
#[cfg(not(feature = "flate2"))]
|
||||||
const METHOD_DEFLATED : Option<zip::CompressionMethod> = None;
|
const METHOD_DEFLATED : Option<zip::CompressionMethod> = None;
|
||||||
|
|
||||||
#[cfg(feature = "bzip2")]
|
#[cfg(feature = "bzip2")]
|
||||||
|
|
|
@ -9,7 +9,7 @@ pub enum CompressionMethod
|
||||||
/// The file is stored (no compression)
|
/// The file is stored (no compression)
|
||||||
Stored,
|
Stored,
|
||||||
/// Deflate in pure rust
|
/// Deflate in pure rust
|
||||||
#[cfg(feature = "deflate")]
|
#[cfg(feature = "flate2")]
|
||||||
Deflated,
|
Deflated,
|
||||||
/// File is compressed using BZIP2 algorithm
|
/// File is compressed using BZIP2 algorithm
|
||||||
#[cfg(feature = "bzip2")]
|
#[cfg(feature = "bzip2")]
|
||||||
|
@ -23,7 +23,7 @@ impl CompressionMethod {
|
||||||
pub fn from_u16(val: u16) -> CompressionMethod {
|
pub fn from_u16(val: u16) -> CompressionMethod {
|
||||||
match val {
|
match val {
|
||||||
0 => CompressionMethod::Stored,
|
0 => CompressionMethod::Stored,
|
||||||
#[cfg(feature = "deflate")]
|
#[cfg(feature = "flate2")]
|
||||||
8 => CompressionMethod::Deflated,
|
8 => CompressionMethod::Deflated,
|
||||||
#[cfg(feature = "bzip2")]
|
#[cfg(feature = "bzip2")]
|
||||||
12 => CompressionMethod::Bzip2,
|
12 => CompressionMethod::Bzip2,
|
||||||
|
@ -35,7 +35,7 @@ impl CompressionMethod {
|
||||||
pub fn to_u16(self) -> u16 {
|
pub fn to_u16(self) -> u16 {
|
||||||
match self {
|
match self {
|
||||||
CompressionMethod::Stored => 0,
|
CompressionMethod::Stored => 0,
|
||||||
#[cfg(feature = "deflate")]
|
#[cfg(feature = "flate2")]
|
||||||
CompressionMethod::Deflated => 8,
|
CompressionMethod::Deflated => 8,
|
||||||
#[cfg(feature = "bzip2")]
|
#[cfg(feature = "bzip2")]
|
||||||
CompressionMethod::Bzip2 => 12,
|
CompressionMethod::Bzip2 => 12,
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
#[cfg(feature = "bzip2")]
|
#[cfg(feature = "bzip2")]
|
||||||
extern crate bzip2;
|
extern crate bzip2;
|
||||||
extern crate crc32fast;
|
extern crate crc32fast;
|
||||||
#[cfg(feature = "deflate")]
|
#[cfg(feature = "flate2")]
|
||||||
extern crate libflate;
|
extern crate flate2;
|
||||||
extern crate podio;
|
extern crate podio;
|
||||||
#[cfg(feature = "time")]
|
#[cfg(feature = "time")]
|
||||||
extern crate time;
|
extern crate time;
|
||||||
|
|
18
src/read.rs
18
src/read.rs
|
@ -13,8 +13,10 @@ use podio::{ReadPodExt, LittleEndian};
|
||||||
use types::{ZipFileData, System, DateTime};
|
use types::{ZipFileData, System, DateTime};
|
||||||
use cp437::FromCp437;
|
use cp437::FromCp437;
|
||||||
|
|
||||||
#[cfg(feature = "deflate")]
|
#[cfg(feature = "flate2")]
|
||||||
use libflate;
|
use flate2;
|
||||||
|
#[cfg(feature = "flate2")]
|
||||||
|
use flate2::read::DeflateDecoder;
|
||||||
|
|
||||||
#[cfg(feature = "bzip2")]
|
#[cfg(feature = "bzip2")]
|
||||||
use bzip2::read::BzDecoder;
|
use bzip2::read::BzDecoder;
|
||||||
|
@ -63,8 +65,8 @@ pub struct ZipArchive<R: Read + io::Seek>
|
||||||
enum ZipFileReader<'a> {
|
enum ZipFileReader<'a> {
|
||||||
NoReader,
|
NoReader,
|
||||||
Stored(Crc32Reader<io::Take<&'a mut Read>>),
|
Stored(Crc32Reader<io::Take<&'a mut Read>>),
|
||||||
#[cfg(feature = "deflate")]
|
#[cfg(feature = "flate2")]
|
||||||
Deflated(Crc32Reader<libflate::deflate::Decoder<io::Take<&'a mut Read>>>),
|
Deflated(Crc32Reader<flate2::read::DeflateDecoder<io::Take<&'a mut Read>>>),
|
||||||
#[cfg(feature = "bzip2")]
|
#[cfg(feature = "bzip2")]
|
||||||
Bzip2(Crc32Reader<BzDecoder<io::Take<&'a mut Read>>>),
|
Bzip2(Crc32Reader<BzDecoder<io::Take<&'a mut Read>>>),
|
||||||
}
|
}
|
||||||
|
@ -94,10 +96,10 @@ fn make_reader<'a>(
|
||||||
reader,
|
reader,
|
||||||
crc32)))
|
crc32)))
|
||||||
},
|
},
|
||||||
#[cfg(feature = "deflate")]
|
#[cfg(feature = "flate2")]
|
||||||
CompressionMethod::Deflated =>
|
CompressionMethod::Deflated =>
|
||||||
{
|
{
|
||||||
let deflate_reader = libflate::deflate::Decoder::new(reader);
|
let deflate_reader = DeflateDecoder::new(reader);
|
||||||
Ok(ZipFileReader::Deflated(Crc32Reader::new(
|
Ok(ZipFileReader::Deflated(Crc32Reader::new(
|
||||||
deflate_reader,
|
deflate_reader,
|
||||||
crc32)))
|
crc32)))
|
||||||
|
@ -416,7 +418,7 @@ fn get_reader<'a>(reader: &'a mut ZipFileReader) -> &'a mut Read {
|
||||||
match *reader {
|
match *reader {
|
||||||
ZipFileReader::NoReader => panic!("ZipFileReader was in an invalid state"),
|
ZipFileReader::NoReader => panic!("ZipFileReader was in an invalid state"),
|
||||||
ZipFileReader::Stored(ref mut r) => r as &mut Read,
|
ZipFileReader::Stored(ref mut r) => r as &mut Read,
|
||||||
#[cfg(feature = "deflate")]
|
#[cfg(feature = "flate2")]
|
||||||
ZipFileReader::Deflated(ref mut r) => r as &mut Read,
|
ZipFileReader::Deflated(ref mut r) => r as &mut Read,
|
||||||
#[cfg(feature = "bzip2")]
|
#[cfg(feature = "bzip2")]
|
||||||
ZipFileReader::Bzip2(ref mut r) => r as &mut Read,
|
ZipFileReader::Bzip2(ref mut r) => r as &mut Read,
|
||||||
|
@ -528,7 +530,7 @@ impl<'a> Drop for ZipFile<'a> {
|
||||||
let mut reader = match innerreader {
|
let mut reader = match innerreader {
|
||||||
ZipFileReader::NoReader => panic!("ZipFileReader was in an invalid state"),
|
ZipFileReader::NoReader => panic!("ZipFileReader was in an invalid state"),
|
||||||
ZipFileReader::Stored(crcreader) => crcreader.into_inner(),
|
ZipFileReader::Stored(crcreader) => crcreader.into_inner(),
|
||||||
#[cfg(feature = "deflate")]
|
#[cfg(feature = "flate2")]
|
||||||
ZipFileReader::Deflated(crcreader) => crcreader.into_inner().into_inner(),
|
ZipFileReader::Deflated(crcreader) => crcreader.into_inner().into_inner(),
|
||||||
#[cfg(feature = "bzip2")]
|
#[cfg(feature = "bzip2")]
|
||||||
ZipFileReader::Bzip2(crcreader) => crcreader.into_inner().into_inner(),
|
ZipFileReader::Bzip2(crcreader) => crcreader.into_inner().into_inner(),
|
||||||
|
|
26
src/write.rs
26
src/write.rs
|
@ -13,8 +13,10 @@ use std::mem;
|
||||||
use time;
|
use time;
|
||||||
use podio::{WritePodExt, LittleEndian};
|
use podio::{WritePodExt, LittleEndian};
|
||||||
|
|
||||||
#[cfg(feature = "deflate")]
|
#[cfg(feature = "flate2")]
|
||||||
use libflate;
|
use flate2;
|
||||||
|
#[cfg(feature = "flate2")]
|
||||||
|
use flate2::write::DeflateEncoder;
|
||||||
|
|
||||||
#[cfg(feature = "bzip2")]
|
#[cfg(feature = "bzip2")]
|
||||||
use bzip2;
|
use bzip2;
|
||||||
|
@ -25,8 +27,8 @@ enum GenericZipWriter<W: Write + io::Seek>
|
||||||
{
|
{
|
||||||
Closed,
|
Closed,
|
||||||
Storer(W),
|
Storer(W),
|
||||||
#[cfg(feature = "deflate")]
|
#[cfg(feature = "flate2")]
|
||||||
Deflater(libflate::deflate::Encoder<W>),
|
Deflater(DeflateEncoder<W>),
|
||||||
#[cfg(feature = "bzip2")]
|
#[cfg(feature = "bzip2")]
|
||||||
Bzip2(BzEncoder<W>),
|
Bzip2(BzEncoder<W>),
|
||||||
}
|
}
|
||||||
|
@ -83,8 +85,8 @@ impl FileOptions {
|
||||||
/// Construct a new FileOptions object
|
/// Construct a new FileOptions object
|
||||||
pub fn default() -> FileOptions {
|
pub fn default() -> FileOptions {
|
||||||
FileOptions {
|
FileOptions {
|
||||||
#[cfg(feature = "deflate")] compression_method: CompressionMethod::Deflated,
|
#[cfg(feature = "flate2")] compression_method: CompressionMethod::Deflated,
|
||||||
#[cfg(not(feature = "deflate"))] compression_method: CompressionMethod::Stored,
|
#[cfg(not(feature = "flate2"))] compression_method: CompressionMethod::Stored,
|
||||||
#[cfg(feature = "time")] last_modified_time: DateTime::from_time(time::now()).unwrap_or(DateTime::default()),
|
#[cfg(feature = "time")] last_modified_time: DateTime::from_time(time::now()).unwrap_or(DateTime::default()),
|
||||||
#[cfg(not(feature = "time"))] last_modified_time: DateTime::default(),
|
#[cfg(not(feature = "time"))] last_modified_time: DateTime::default(),
|
||||||
permissions: None,
|
permissions: None,
|
||||||
|
@ -367,8 +369,8 @@ impl<W: Write+io::Seek> GenericZipWriter<W>
|
||||||
let bare = match mem::replace(self, GenericZipWriter::Closed)
|
let bare = match mem::replace(self, GenericZipWriter::Closed)
|
||||||
{
|
{
|
||||||
GenericZipWriter::Storer(w) => w,
|
GenericZipWriter::Storer(w) => w,
|
||||||
#[cfg(feature = "deflate")]
|
#[cfg(feature = "flate2")]
|
||||||
GenericZipWriter::Deflater(w) => w.finish().into_result()?,
|
GenericZipWriter::Deflater(w) => w.finish()?,
|
||||||
#[cfg(feature = "bzip2")]
|
#[cfg(feature = "bzip2")]
|
||||||
GenericZipWriter::Bzip2(w) => w.finish()?,
|
GenericZipWriter::Bzip2(w) => w.finish()?,
|
||||||
GenericZipWriter::Closed => Err(io::Error::new(io::ErrorKind::BrokenPipe, "ZipWriter was already closed"))?,
|
GenericZipWriter::Closed => Err(io::Error::new(io::ErrorKind::BrokenPipe, "ZipWriter was already closed"))?,
|
||||||
|
@ -377,8 +379,8 @@ impl<W: Write+io::Seek> GenericZipWriter<W>
|
||||||
*self = match compression
|
*self = match compression
|
||||||
{
|
{
|
||||||
CompressionMethod::Stored => GenericZipWriter::Storer(bare),
|
CompressionMethod::Stored => GenericZipWriter::Storer(bare),
|
||||||
#[cfg(feature = "deflate")]
|
#[cfg(feature = "flate2")]
|
||||||
CompressionMethod::Deflated => GenericZipWriter::Deflater(libflate::deflate::Encoder::new(bare)),
|
CompressionMethod::Deflated => GenericZipWriter::Deflater(DeflateEncoder::new(bare, flate2::Compression::default())),
|
||||||
#[cfg(feature = "bzip2")]
|
#[cfg(feature = "bzip2")]
|
||||||
CompressionMethod::Bzip2 => GenericZipWriter::Bzip2(BzEncoder::new(bare, bzip2::Compression::Default)),
|
CompressionMethod::Bzip2 => GenericZipWriter::Bzip2(BzEncoder::new(bare, bzip2::Compression::Default)),
|
||||||
CompressionMethod::Unsupported(..) => return Err(ZipError::UnsupportedArchive("Unsupported compression")),
|
CompressionMethod::Unsupported(..) => return Err(ZipError::UnsupportedArchive("Unsupported compression")),
|
||||||
|
@ -390,7 +392,7 @@ impl<W: Write+io::Seek> GenericZipWriter<W>
|
||||||
fn ref_mut(&mut self) -> Option<&mut Write> {
|
fn ref_mut(&mut self) -> Option<&mut Write> {
|
||||||
match *self {
|
match *self {
|
||||||
GenericZipWriter::Storer(ref mut w) => Some(w as &mut Write),
|
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),
|
GenericZipWriter::Deflater(ref mut w) => Some(w as &mut Write),
|
||||||
#[cfg(feature = "bzip2")]
|
#[cfg(feature = "bzip2")]
|
||||||
GenericZipWriter::Bzip2(ref mut w) => Some(w as &mut Write),
|
GenericZipWriter::Bzip2(ref mut w) => Some(w as &mut Write),
|
||||||
|
@ -419,7 +421,7 @@ impl<W: Write+io::Seek> GenericZipWriter<W>
|
||||||
fn current_compression(&self) -> Option<CompressionMethod> {
|
fn current_compression(&self) -> Option<CompressionMethod> {
|
||||||
match *self {
|
match *self {
|
||||||
GenericZipWriter::Storer(..) => Some(CompressionMethod::Stored),
|
GenericZipWriter::Storer(..) => Some(CompressionMethod::Stored),
|
||||||
#[cfg(feature = "deflate")]
|
#[cfg(feature = "flate2")]
|
||||||
GenericZipWriter::Deflater(..) => Some(CompressionMethod::Deflated),
|
GenericZipWriter::Deflater(..) => Some(CompressionMethod::Deflated),
|
||||||
#[cfg(feature = "bzip2")]
|
#[cfg(feature = "bzip2")]
|
||||||
GenericZipWriter::Bzip2(..) => Some(CompressionMethod::Bzip2),
|
GenericZipWriter::Bzip2(..) => Some(CompressionMethod::Bzip2),
|
||||||
|
|
Loading…
Add table
Reference in a new issue