diff --git a/src/reader.rs b/src/reader.rs index 850320aa..c1f58f40 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -1,9 +1,9 @@ use crc32::Crc32Reader; use types::ZipFile; -use compression; +use compression::CompressionMethod; use spec; use reader_spec; -use result::ZipResult; +use result::{ZipResult, ZipError}; use std::io; use std::cell::RefCell; use flate2::FlateReader; @@ -40,7 +40,7 @@ pub struct ZipReader fn unsupported_zip_error(detail: &'static str) -> ZipResult { - Err(::result::UnsupportedZipFile(detail)) + Err(ZipError::UnsupportedZipFile(detail)) } impl ZipReader @@ -80,7 +80,7 @@ impl ZipReader let mut inner_reader = match self.inner.try_borrow_mut() { Some(reader) => reader, - None => return Err(::result::ReaderUnavailable), + None => return Err(ZipError::ReaderUnavailable), }; let pos = file.data_start as i64; @@ -95,7 +95,7 @@ impl ZipReader let reader = match file.compression_method { - compression::Stored => + CompressionMethod::Stored => { box Crc32Reader::new( @@ -103,7 +103,7 @@ impl ZipReader file.crc32) as Box }, - compression::Deflated => + CompressionMethod::Deflated => { let deflate_reader = limit_reader.deflate_decode(); box diff --git a/src/reader_spec.rs b/src/reader_spec.rs index 48035652..75352ab3 100644 --- a/src/reader_spec.rs +++ b/src/reader_spec.rs @@ -1,7 +1,7 @@ use std::io; -use result::ZipResult; -use compression; +use result::{ZipResult, ZipError}; use types::ZipFile; +use compression::CompressionMethod; use spec; use util; @@ -11,7 +11,7 @@ pub fn central_header_to_zip_file(reader: &mut R) -> ZipResult(reader: &mut R) -> ZipResult(reader: &mut R) -> ZipResult for ZipError { fn from_error(err: io::IoError) -> ZipError { - Io(err) + ZipError::Io(err) } } @@ -36,10 +36,10 @@ impl error::Error for ZipError { match *self { - Io(ref io_err) => io_err.description(), - InvalidZipFile(..) => "Invalid Zip File", - UnsupportedZipFile(..) => "Unsupported Zip File", - ReaderUnavailable => "No reader available", + ZipError::Io(ref io_err) => io_err.description(), + ZipError::InvalidZipFile(..) => "Invalid Zip File", + ZipError::UnsupportedZipFile(..) => "Unsupported Zip File", + ZipError::ReaderUnavailable => "No reader available", } } @@ -47,10 +47,10 @@ impl error::Error for ZipError { match *self { - Io(ref io_err) => io_err.detail(), - InvalidZipFile(detail) | - UnsupportedZipFile(detail) => Some(detail.to_string()), - ReaderUnavailable => None, + ZipError::Io(ref io_err) => io_err.detail(), + ZipError::InvalidZipFile(detail) | + ZipError::UnsupportedZipFile(detail) => Some(detail.to_string()), + ZipError::ReaderUnavailable => None, } } @@ -58,7 +58,7 @@ impl error::Error for ZipError { match *self { - Io(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/spec.rs b/src/spec.rs index c8292574..d83bc47b 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -1,5 +1,5 @@ use std::io; -use result::ZipResult; +use result::{ZipResult, ZipError}; use std::iter::range_step_inclusive; pub static LOCAL_FILE_HEADER_SIGNATURE : u32 = 0x04034b50; @@ -24,7 +24,7 @@ impl CentralDirectoryEnd let magic = try!(reader.read_le_u32()); if magic != CENTRAL_DIRECTORY_END_SIGNATURE { - return Err(::result::UnsupportedZipFile("Invalid digital signature header")) + return Err(ZipError::UnsupportedZipFile("Invalid digital signature header")) } let disk_number = try!(reader.read_le_u16()); let disk_with_central_directory = try!(reader.read_le_u16()); @@ -69,7 +69,7 @@ impl CentralDirectoryEnd } } } - Err(::result::UnsupportedZipFile("Could not find central directory end")) + Err(ZipError::UnsupportedZipFile("Could not find central directory end")) } pub fn write(&self, writer: &mut T) -> ZipResult<()> diff --git a/src/writer.rs b/src/writer.rs index 17edeffa..23f54734 100644 --- a/src/writer.rs +++ b/src/writer.rs @@ -1,9 +1,9 @@ -use compression; +use compression::CompressionMethod; use types::ZipFile; use spec; use writer_spec; use crc32; -use result::ZipResult; +use result::{ZipResult, ZipError}; use std::default::Default; use std::io; use std::mem; @@ -63,9 +63,9 @@ impl Writer for ZipWriter self.stats.update(buf); match self.inner { - Storer(ref mut w) => w.write(buf), - Deflater(ref mut w) => w.write(buf), - Closed => Err(io::standard_error(io::Closed)), + GenericZipWriter::Storer(ref mut w) => w.write(buf), + GenericZipWriter::Deflater(ref mut w) => w.write(buf), + GenericZipWriter::Closed => Err(io::standard_error(io::Closed)), } } } @@ -88,14 +88,14 @@ impl ZipWriter { ZipWriter { - inner: Storer(inner), + inner: GenericZipWriter::Storer(inner), files: Vec::new(), stats: Default::default(), } } /// Start a new file for with the requested compression method. - pub fn start_file(&mut self, name: &str, compression: compression::CompressionMethod) -> ZipResult<()> + pub fn start_file(&mut self, name: &str, compression: CompressionMethod) -> ZipResult<()> { try!(self.finish_file()); @@ -135,7 +135,7 @@ impl ZipWriter fn finish_file(&mut self) -> ZipResult<()> { - try!(self.inner.switch_to(compression::Stored)); + try!(self.inner.switch_to(CompressionMethod::Stored)); let writer = self.inner.get_plain(); let file = match self.files.last_mut() @@ -159,7 +159,7 @@ impl ZipWriter pub fn finish(mut self) -> ZipResult { try!(self.finalize()); - let inner = mem::replace(&mut self.inner, Closed); + let inner = mem::replace(&mut self.inner, GenericZipWriter::Closed); Ok(inner.unwrap()) } @@ -213,20 +213,20 @@ impl Drop for ZipWriter impl GenericZipWriter { - fn switch_to(&mut self, compression: compression::CompressionMethod) -> ZipResult<()> + fn switch_to(&mut self, compression: CompressionMethod) -> ZipResult<()> { - let bare = match mem::replace(self, Closed) + let bare = match mem::replace(self, GenericZipWriter::Closed) { - Storer(w) => w, - Deflater(w) => try!(w.finish()), - Closed => try!(Err(io::standard_error(io::Closed))), + GenericZipWriter::Storer(w) => w, + GenericZipWriter::Deflater(w) => try!(w.finish()), + GenericZipWriter::Closed => try!(Err(io::standard_error(io::Closed))), }; *self = match compression { - compression::Stored => Storer(bare), - compression::Deflated => Deflater(bare.deflate_encode(flate2::Default)), - _ => return Err(::result::UnsupportedZipFile("Unsupported compression")), + CompressionMethod::Stored => GenericZipWriter::Storer(bare), + CompressionMethod::Deflated => GenericZipWriter::Deflater(bare.deflate_encode(flate2::Default)), + _ => return Err(ZipError::UnsupportedZipFile("Unsupported compression")), }; Ok(()) @@ -236,7 +236,7 @@ impl GenericZipWriter { match *self { - Closed => true, + GenericZipWriter::Closed => true, _ => false, } } @@ -245,7 +245,7 @@ impl GenericZipWriter { match *self { - Storer(ref mut w) => w, + GenericZipWriter::Storer(ref mut w) => w, _ => panic!("Should have switched to stored beforehand"), } } @@ -254,7 +254,7 @@ impl GenericZipWriter { match self { - Storer(w) => w, + GenericZipWriter::Storer(w) => w, _ => panic!("Should have switched to stored beforehand"), } }