Merge branch 'flate2' of https://github.com/jonpas/zip-rs
This commit is contained in:
commit
f9c2c64faa
4 changed files with 16 additions and 10 deletions
|
@ -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/rust_backend"]
|
||||
deflate-miniz = ["flate2/default"]
|
||||
deflate-zlib = ["flate2/zlib"]
|
||||
default = ["bzip2", "deflate", "time"]
|
||||
|
||||
[[bench]]
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
extern crate bzip2;
|
||||
extern crate crc32fast;
|
||||
#[cfg(feature = "deflate")]
|
||||
extern crate libflate;
|
||||
extern crate flate2;
|
||||
extern crate podio;
|
||||
#[cfg(feature = "time")]
|
||||
extern crate time;
|
||||
|
|
|
@ -14,7 +14,9 @@ use types::{ZipFileData, System, DateTime};
|
|||
use cp437::FromCp437;
|
||||
|
||||
#[cfg(feature = "deflate")]
|
||||
use libflate;
|
||||
use flate2;
|
||||
#[cfg(feature = "deflate")]
|
||||
use flate2::read::DeflateDecoder;
|
||||
|
||||
#[cfg(feature = "bzip2")]
|
||||
use bzip2::read::BzDecoder;
|
||||
|
@ -64,7 +66,7 @@ enum ZipFileReader<'a> {
|
|||
NoReader,
|
||||
Stored(Crc32Reader<io::Take<&'a mut Read>>),
|
||||
#[cfg(feature = "deflate")]
|
||||
Deflated(Crc32Reader<libflate::deflate::Decoder<io::Take<&'a mut Read>>>),
|
||||
Deflated(Crc32Reader<flate2::read::DeflateDecoder<io::Take<&'a mut Read>>>),
|
||||
#[cfg(feature = "bzip2")]
|
||||
Bzip2(Crc32Reader<BzDecoder<io::Take<&'a mut Read>>>),
|
||||
}
|
||||
|
@ -97,7 +99,7 @@ fn make_reader<'a>(
|
|||
#[cfg(feature = "deflate")]
|
||||
CompressionMethod::Deflated =>
|
||||
{
|
||||
let deflate_reader = libflate::deflate::Decoder::new(reader);
|
||||
let deflate_reader = DeflateDecoder::new(reader);
|
||||
Ok(ZipFileReader::Deflated(Crc32Reader::new(
|
||||
deflate_reader,
|
||||
crc32)))
|
||||
|
|
10
src/write.rs
10
src/write.rs
|
@ -14,7 +14,9 @@ use time;
|
|||
use podio::{WritePodExt, LittleEndian};
|
||||
|
||||
#[cfg(feature = "deflate")]
|
||||
use libflate;
|
||||
use flate2;
|
||||
#[cfg(feature = "deflate")]
|
||||
use flate2::write::DeflateEncoder;
|
||||
|
||||
#[cfg(feature = "bzip2")]
|
||||
use bzip2;
|
||||
|
@ -26,7 +28,7 @@ enum GenericZipWriter<W: Write + io::Seek>
|
|||
Closed,
|
||||
Storer(W),
|
||||
#[cfg(feature = "deflate")]
|
||||
Deflater(libflate::deflate::Encoder<W>),
|
||||
Deflater(DeflateEncoder<W>),
|
||||
#[cfg(feature = "bzip2")]
|
||||
Bzip2(BzEncoder<W>),
|
||||
}
|
||||
|
@ -374,7 +376,7 @@ impl<W: Write+io::Seek> GenericZipWriter<W>
|
|||
{
|
||||
GenericZipWriter::Storer(w) => w,
|
||||
#[cfg(feature = "deflate")]
|
||||
GenericZipWriter::Deflater(w) => w.finish().into_result()?,
|
||||
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"))?,
|
||||
|
@ -384,7 +386,7 @@ impl<W: Write+io::Seek> GenericZipWriter<W>
|
|||
{
|
||||
CompressionMethod::Stored => GenericZipWriter::Storer(bare),
|
||||
#[cfg(feature = "deflate")]
|
||||
CompressionMethod::Deflated => GenericZipWriter::Deflater(libflate::deflate::Encoder::new(bare)),
|
||||
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")),
|
||||
|
|
Loading…
Add table
Reference in a new issue