add libflate feature

This commit is contained in:
Mackenzie Clark 2018-11-04 10:12:16 -08:00
parent 27c79de0f8
commit c05b6c2317
9 changed files with 47 additions and 50 deletions

2
.gitignore vendored
View file

@ -1,2 +1,4 @@
Cargo.lock
target
\.idea/

View file

@ -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:

View file

@ -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"]

View file

@ -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"

View file

@ -17,16 +17,16 @@ fn main() {
const METHOD_STORED : Option<zip::CompressionMethod> = Some(zip::CompressionMethod::Stored);
#[cfg(feature = "flate2")]
const METHOD_DEFLATED : Option<zip::CompressionMethod> = Some(zip::CompressionMethod::Deflated);
#[cfg(not(feature = "flate2"))]
const METHOD_DEFLATED : Option<zip::CompressionMethod> = None;
#[cfg(feature = "bzip2")]
const METHOD_BZIP2 : Option<zip::CompressionMethod> = Some(zip::CompressionMethod::Bzip2);
#[cfg(not(feature = "bzip2"))]
const METHOD_BZIP2 : Option<zip::CompressionMethod> = None;
#[cfg(feature = "deflate")]
const METHOD_DEFLATED : Option<zip::CompressionMethod> = Some(zip::CompressionMethod::Deflated);
#[cfg(not(feature = "deflate"))]
const METHOD_DEFLATED : Option<zip::CompressionMethod> = 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),

View file

@ -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<CompressionMethod> {
vec![CompressionMethod::Stored, CompressionMethod::Deflated]
}
#[cfg(all(not(feature = "flate2"), feature = "bzip2"))]
#[cfg(all(not(feature = "deflate"), feature = "bzip2"))]
fn methods() -> Vec<CompressionMethod> {
vec![CompressionMethod::Stored, CompressionMethod::Bzip2]
}
#[cfg(all(feature = "bzip2", feature = "flate2"))]
#[cfg(all(feature = "bzip2", feature = "deflate"))]
fn methods() -> Vec<CompressionMethod> {
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<CompressionMethod> {
vec![CompressionMethod::Stored]
}

View file

@ -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;

View file

@ -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<R: Read + io::Seek>
enum ZipFileReader<'a> {
NoReader,
Stored(Crc32Reader<io::Take<&'a mut Read>>),
#[cfg(feature = "flate2")]
Deflated(Crc32Reader<flate2::read::DeflateDecoder<io::Take<&'a mut Read>>>),
#[cfg(feature = "deflate")]
Deflated(Crc32Reader<Decoder<io::Take<&'a mut Read>>>),
#[cfg(feature = "bzip2")]
Bzip2(Crc32Reader<BzDecoder<io::Take<&'a mut Read>>>),
}
@ -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(),

View file

@ -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<W: Write + io::Seek>
{
Closed,
Storer(W),
#[cfg(feature = "flate2")]
Deflater(DeflateEncoder<W>),
#[cfg(feature = "deflate")]
Deflater(libflate::deflate::Encoder<W>),
#[cfg(feature = "bzip2")]
Bzip2(BzEncoder<W>),
}
@ -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<W: Write+io::Seek> GenericZipWriter<W>
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<W: Write+io::Seek> GenericZipWriter<W>
*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<W: Write+io::Seek> GenericZipWriter<W>
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<W: Write+io::Seek> GenericZipWriter<W>
fn current_compression(&self) -> Option<CompressionMethod> {
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),