Merge branch 'add-libflate' of https://github.com/xmclark/zip-rs
This commit is contained in:
commit
4ae1db992c
9 changed files with 39 additions and 48 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +1,4 @@
|
||||||
Cargo.lock
|
Cargo.lock
|
||||||
target
|
target
|
||||||
|
|
||||||
|
\.idea/
|
||||||
|
|
|
@ -12,13 +12,9 @@ notifications:
|
||||||
on_failure: always
|
on_failure: always
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- |
|
- cargo test
|
||||||
[ "$TRAVIS_RUST_VERSION" = "1.20.0" ] || cargo test
|
|
||||||
- cargo test --no-default-features
|
- cargo test --no-default-features
|
||||||
- |
|
- cargo doc --no-deps
|
||||||
[ "$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"
|
|
||||||
- rustdoc --test README.md -L target/debug
|
- rustdoc --test README.md -L target/debug
|
||||||
|
|
||||||
after_success:
|
after_success:
|
||||||
|
|
|
@ -12,17 +12,15 @@ Library to support the reading and writing of zip files.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
flate2 = { version = "1.0", default-features = false, optional = true }
|
|
||||||
time = "0.1"
|
time = "0.1"
|
||||||
podio = "0.1"
|
podio = "0.1"
|
||||||
msdos_time = "0.1"
|
msdos_time = "0.1"
|
||||||
bzip2 = { version = "0.3", optional = true }
|
bzip2 = { version = "0.3", optional = true }
|
||||||
|
libflate = { version = "0.1.16", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
walkdir = "1.0"
|
walkdir = "1.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
deflate = ["flate2", "flate2/rust_backend"]
|
deflate = ["libflate"]
|
||||||
deflate-miniz = ["flate2", "flate2/miniz-sys"]
|
|
||||||
deflate-zlib = ["flate2", "flate2/zlib"]
|
|
||||||
default = ["bzip2", "deflate"]
|
default = ["bzip2", "deflate"]
|
||||||
|
|
|
@ -42,4 +42,3 @@ build: false
|
||||||
test_script:
|
test_script:
|
||||||
- cargo test
|
- cargo test
|
||||||
- cargo test --no-default-features
|
- cargo test --no-default-features
|
||||||
- cargo test --no-default-features --features "deflate-miniz"
|
|
||||||
|
|
|
@ -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 = "flate2")]
|
#[cfg(feature = "deflate")]
|
||||||
const METHOD_DEFLATED : Option<zip::CompressionMethod> = Some(zip::CompressionMethod::Deflated);
|
const METHOD_DEFLATED : Option<zip::CompressionMethod> = Some(zip::CompressionMethod::Deflated);
|
||||||
#[cfg(not(feature = "flate2"))]
|
#[cfg(not(feature = "deflate"))]
|
||||||
const METHOD_DEFLATED : Option<zip::CompressionMethod> = None;
|
const METHOD_DEFLATED : Option<zip::CompressionMethod> = None;
|
||||||
|
|
||||||
#[cfg(feature = "bzip2")]
|
#[cfg(feature = "bzip2")]
|
||||||
|
|
|
@ -8,8 +8,8 @@ pub enum CompressionMethod
|
||||||
{
|
{
|
||||||
/// The file is stored (no compression)
|
/// The file is stored (no compression)
|
||||||
Stored,
|
Stored,
|
||||||
/// The file is Deflated
|
/// Deflate in pure rust
|
||||||
#[cfg(feature = "flate2")]
|
#[cfg(feature = "deflate")]
|
||||||
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 = "flate2")]
|
#[cfg(feature = "deflate")]
|
||||||
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 = "flate2")]
|
#[cfg(feature = "deflate")]
|
||||||
CompressionMethod::Deflated => 8,
|
CompressionMethod::Deflated => 8,
|
||||||
#[cfg(feature = "bzip2")]
|
#[cfg(feature = "bzip2")]
|
||||||
CompressionMethod::Bzip2 => 12,
|
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> {
|
fn methods() -> Vec<CompressionMethod> {
|
||||||
vec![CompressionMethod::Stored, CompressionMethod::Deflated]
|
vec![CompressionMethod::Stored, CompressionMethod::Deflated]
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(not(feature = "flate2"), feature = "bzip2"))]
|
#[cfg(all(not(feature = "deflate"), feature = "bzip2"))]
|
||||||
fn methods() -> Vec<CompressionMethod> {
|
fn methods() -> Vec<CompressionMethod> {
|
||||||
vec![CompressionMethod::Stored, CompressionMethod::Bzip2]
|
vec![CompressionMethod::Stored, CompressionMethod::Bzip2]
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "bzip2", feature = "flate2"))]
|
#[cfg(all(feature = "bzip2", feature = "deflate"))]
|
||||||
fn methods() -> Vec<CompressionMethod> {
|
fn methods() -> Vec<CompressionMethod> {
|
||||||
vec![CompressionMethod::Stored, CompressionMethod::Deflated, CompressionMethod::Bzip2]
|
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> {
|
fn methods() -> Vec<CompressionMethod> {
|
||||||
vec![CompressionMethod::Stored]
|
vec![CompressionMethod::Stored]
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
|
|
||||||
#[cfg(feature = "bzip2")]
|
#[cfg(feature = "bzip2")]
|
||||||
extern crate bzip2;
|
extern crate bzip2;
|
||||||
#[cfg(feature = "flate2")]
|
#[cfg(feature = "deflate")]
|
||||||
extern crate flate2;
|
extern crate libflate;
|
||||||
extern crate msdos_time;
|
extern crate msdos_time;
|
||||||
extern crate podio;
|
extern crate podio;
|
||||||
extern crate time;
|
extern crate time;
|
||||||
|
|
20
src/read.rs
20
src/read.rs
|
@ -14,10 +14,8 @@ use types::{ZipFileData, System, DateTime};
|
||||||
use cp437::FromCp437;
|
use cp437::FromCp437;
|
||||||
use msdos_time::MsDosDateTime;
|
use msdos_time::MsDosDateTime;
|
||||||
|
|
||||||
#[cfg(feature = "flate2")]
|
#[cfg(feature = "deflate")]
|
||||||
use flate2;
|
use libflate;
|
||||||
#[cfg(feature = "flate2")]
|
|
||||||
use flate2::read::DeflateDecoder;
|
|
||||||
|
|
||||||
#[cfg(feature = "bzip2")]
|
#[cfg(feature = "bzip2")]
|
||||||
use bzip2::read::BzDecoder;
|
use bzip2::read::BzDecoder;
|
||||||
|
@ -66,8 +64,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 = "flate2")]
|
#[cfg(feature = "deflate")]
|
||||||
Deflated(Crc32Reader<flate2::read::DeflateDecoder<io::Take<&'a mut Read>>>),
|
Deflated(Crc32Reader<libflate::deflate::Decoder<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>>>),
|
||||||
}
|
}
|
||||||
|
@ -97,10 +95,10 @@ fn make_reader<'a>(
|
||||||
reader,
|
reader,
|
||||||
crc32)))
|
crc32)))
|
||||||
},
|
},
|
||||||
#[cfg(feature = "flate2")]
|
#[cfg(feature = "deflate")]
|
||||||
CompressionMethod::Deflated =>
|
CompressionMethod::Deflated =>
|
||||||
{
|
{
|
||||||
let deflate_reader = DeflateDecoder::new(reader);
|
let deflate_reader = libflate::deflate::Decoder::new(reader);
|
||||||
Ok(ZipFileReader::Deflated(Crc32Reader::new(
|
Ok(ZipFileReader::Deflated(Crc32Reader::new(
|
||||||
deflate_reader,
|
deflate_reader,
|
||||||
crc32)))
|
crc32)))
|
||||||
|
@ -419,14 +417,14 @@ 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 = "flate2")]
|
#[cfg(feature = "deflate")]
|
||||||
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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Methods for retreiving information on zip files
|
/// Methods for retrieving information on zip files
|
||||||
impl<'a> ZipFile<'a> {
|
impl<'a> ZipFile<'a> {
|
||||||
fn get_reader(&mut self) -> &mut Read {
|
fn get_reader(&mut self) -> &mut Read {
|
||||||
get_reader(&mut self.reader)
|
get_reader(&mut self.reader)
|
||||||
|
@ -523,7 +521,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 = "flate2")]
|
#[cfg(feature = "deflate")]
|
||||||
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
|
@ -12,10 +12,8 @@ use std::mem;
|
||||||
use time;
|
use time;
|
||||||
use podio::{WritePodExt, LittleEndian};
|
use podio::{WritePodExt, LittleEndian};
|
||||||
|
|
||||||
#[cfg(feature = "flate2")]
|
#[cfg(feature = "deflate")]
|
||||||
use flate2;
|
use libflate;
|
||||||
#[cfg(feature = "flate2")]
|
|
||||||
use flate2::write::DeflateEncoder;
|
|
||||||
|
|
||||||
#[cfg(feature = "bzip2")]
|
#[cfg(feature = "bzip2")]
|
||||||
use bzip2;
|
use bzip2;
|
||||||
|
@ -28,8 +26,8 @@ enum GenericZipWriter<W: Write + io::Seek>
|
||||||
{
|
{
|
||||||
Closed,
|
Closed,
|
||||||
Storer(W),
|
Storer(W),
|
||||||
#[cfg(feature = "flate2")]
|
#[cfg(feature = "deflate")]
|
||||||
Deflater(DeflateEncoder<W>),
|
Deflater(libflate::deflate::Encoder<W>),
|
||||||
#[cfg(feature = "bzip2")]
|
#[cfg(feature = "bzip2")]
|
||||||
Bzip2(BzEncoder<W>),
|
Bzip2(BzEncoder<W>),
|
||||||
}
|
}
|
||||||
|
@ -82,7 +80,7 @@ pub struct FileOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FileOptions {
|
impl FileOptions {
|
||||||
#[cfg(feature = "flate2")]
|
#[cfg(feature = "deflate")]
|
||||||
/// Construct a new FileOptions object
|
/// Construct a new FileOptions object
|
||||||
pub fn default() -> FileOptions {
|
pub fn default() -> FileOptions {
|
||||||
FileOptions {
|
FileOptions {
|
||||||
|
@ -92,7 +90,7 @@ impl FileOptions {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "flate2"))]
|
#[cfg(not(feature = "deflate"))]
|
||||||
/// Construct a new FileOptions object
|
/// Construct a new FileOptions object
|
||||||
pub fn default() -> FileOptions {
|
pub fn default() -> FileOptions {
|
||||||
FileOptions {
|
FileOptions {
|
||||||
|
@ -357,8 +355,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 = "flate2")]
|
#[cfg(feature = "deflate")]
|
||||||
GenericZipWriter::Deflater(w) => w.finish()?,
|
GenericZipWriter::Deflater(w) => w.finish().into_result()?,
|
||||||
#[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"))?,
|
||||||
|
@ -367,8 +365,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 = "flate2")]
|
#[cfg(feature = "deflate")]
|
||||||
CompressionMethod::Deflated => GenericZipWriter::Deflater(DeflateEncoder::new(bare, flate2::Compression::default())),
|
CompressionMethod::Deflated => GenericZipWriter::Deflater(libflate::deflate::Encoder::new(bare)),
|
||||||
#[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")),
|
||||||
|
@ -380,7 +378,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 = "flate2")]
|
#[cfg(feature = "deflate")]
|
||||||
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),
|
||||||
|
@ -409,7 +407,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 = "flate2")]
|
#[cfg(feature = "deflate")]
|
||||||
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