diff --git a/Cargo.toml b/Cargo.toml index 04829961..4aa332f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,5 +11,8 @@ Library to support the reading and writing of zip files. [dependencies] flate2 = "*" -bzip2 = "*" time = "*" + +[dependencies.bzip2] +git = "https://github.com/mvdnes/bzip2-rs" +branch = "new_io" diff --git a/src/ioconverter.rs b/src/ioconverter.rs deleted file mode 100644 index 4a0e258d..00000000 --- a/src/ioconverter.rs +++ /dev/null @@ -1,60 +0,0 @@ -use std::io; -use std::io::prelude::*; -use std::old_io; - -pub struct IoConverter { - inner: T, -} - -impl IoConverter { - pub fn new(inner: T) -> IoConverter { - IoConverter { inner: inner, } - } - pub fn into_inner(self) -> T { - self.inner - } -} - -impl Writer for IoConverter { - fn write_all(&mut self, buf: &[u8]) -> old_io::IoResult<()> { - match self.inner.write_all(buf) { - Ok(()) => Ok(()), - Err(..) => Err(old_io::standard_error(old_io::OtherIoError)), - } - } -} - -impl Write for IoConverter { - fn write(&mut self, buf: &[u8]) -> io::Result { - match self.inner.write_all(buf) { - Ok(()) => Ok(buf.len()), - Err(..) => Err(io::Error::new(io::ErrorKind::Other, "Some writing error", None)), - } - } - fn flush(&mut self) -> io::Result<()> { - match self.inner.flush() { - Ok(()) => Ok(()), - Err(..) => Err(io::Error::new(io::ErrorKind::Other, "Some flushing error", None)), - } - } -} - -impl Read for IoConverter { - fn read(&mut self, buf: &mut [u8]) -> io::Result { - match self.inner.read(buf) { - Ok(v) => Ok(v), - Err(ref e) if e.kind == old_io::EndOfFile => Ok(0), - Err(..) => Err(io::Error::new(io::ErrorKind::Other, "Some reading error", None)), - } - } -} - -impl Reader for IoConverter { - fn read(&mut self, buf: &mut [u8]) -> old_io::IoResult { - match self.inner.read(buf) { - Ok(0) if buf.len() > 0 => Err(old_io::standard_error(old_io::EndOfFile)), - Ok(v) => Ok(v), - Err(..) => Err(old_io::standard_error(old_io::OtherIoError)), - } - } -} diff --git a/src/lib.rs b/src/lib.rs index 44618990..41824950 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,4 +25,3 @@ pub mod compression; mod writer; mod cp437; pub mod result; -mod ioconverter; diff --git a/src/reader.rs b/src/reader.rs index ca8725d6..b3b12b0b 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -10,7 +10,6 @@ use std::cell::{RefCell, BorrowState}; use std::collections::HashMap; use flate2::FlateReadExt; use bzip2::reader::BzDecompressor; -use ioconverter::IoConverter; /// Wrapper for reading the contents of a ZIP file. /// @@ -130,7 +129,7 @@ impl ZipReader }, CompressionMethod::Bzip2 => { - let bzip2_reader = IoConverter::new(BzDecompressor::new(IoConverter::new(limit_reader))); + let bzip2_reader = BzDecompressor::new(limit_reader); Box::new( Crc32Reader::new( bzip2_reader, diff --git a/src/result.rs b/src/result.rs index 2d1a5c91..0041d1c0 100644 --- a/src/result.rs +++ b/src/result.rs @@ -1,6 +1,5 @@ //! Error types that can be emitted from this library -use std::old_io::IoError; use std::io; use std::error; use std::fmt; @@ -12,9 +11,6 @@ pub type ZipResult = Result; #[derive(Debug)] pub enum ZipError { - /// An Error caused by old I/O - OldIo(IoError), - /// An Error caused by I/O Io(io::Error), @@ -37,9 +33,6 @@ impl ZipError match *self { - ZipError::OldIo(ref io_err) => { - ("OldIo Error: ".to_string() + io_err.description()).into_cow() - }, ZipError::Io(ref io_err) => { ("Io Error: ".to_string() + io_err.description()).into_cow() }, @@ -53,14 +46,6 @@ impl ZipError } } -impl error::FromError for ZipError -{ - fn from_error(err: IoError) -> ZipError - { - ZipError::OldIo(err) - } -} - impl error::FromError for ZipError { fn from_error(err: io::Error) -> ZipError @@ -83,7 +68,6 @@ impl error::Error for ZipError { match *self { - ZipError::OldIo(ref io_err) => io_err.description(), ZipError::Io(ref io_err) => io_err.description(), ZipError::InvalidZipFile(..) => "Invalid Zip File", ZipError::UnsupportedZipFile(..) => "Unsupported Zip File", @@ -95,7 +79,6 @@ impl error::Error for ZipError { match *self { - ZipError::OldIo(ref io_err) => Some(io_err as &error::Error), ZipError::Io(ref io_err) => Some(io_err as &error::Error), _ => None, } diff --git a/src/writer.rs b/src/writer.rs index 481dbc88..4281b6e6 100644 --- a/src/writer.rs +++ b/src/writer.rs @@ -14,14 +14,13 @@ use flate2::FlateWriteExt; use flate2::write::DeflateEncoder; use bzip2; use bzip2::writer::BzCompressor; -use ioconverter::IoConverter; enum GenericZipWriter { Closed, Storer(W), Deflater(DeflateEncoder), - Bzip2(IoConverter>>), + Bzip2(BzCompressor), } /// Generator for ZIP files. @@ -236,7 +235,7 @@ impl GenericZipWriter { GenericZipWriter::Storer(w) => w, GenericZipWriter::Deflater(w) => try!(w.finish()), - GenericZipWriter::Bzip2(w) => match w.into_inner().into_inner() { Ok(r) => r.into_inner(), Err((_, err)) => try!(Err(err)) }, + GenericZipWriter::Bzip2(w) => match w.into_inner() { Ok(r) => r, Err((_, err)) => try!(Err(err)) }, GenericZipWriter::Closed => try!(Err(io::Error::new(io::ErrorKind::BrokenPipe, "ZipWriter was already closed", None))), }; @@ -244,7 +243,7 @@ impl GenericZipWriter { CompressionMethod::Stored => GenericZipWriter::Storer(bare), CompressionMethod::Deflated => GenericZipWriter::Deflater(bare.deflate_encode(flate2::Compression::Default)), - CompressionMethod::Bzip2 => GenericZipWriter::Bzip2(IoConverter::new(BzCompressor::new(IoConverter::new(bare), bzip2::CompressionLevel::Default))), + CompressionMethod::Bzip2 => GenericZipWriter::Bzip2(BzCompressor::new(bare, bzip2::CompressionLevel::Default)), _ => return Err(ZipError::UnsupportedZipFile("Unsupported compression")), };