Cleaned the code of ZipReader's constructor

This commit is contained in:
Mathijs van de Nes 2014-09-10 16:40:13 +02:00
parent e9d42a9dc9
commit 7ce0f5b21f

View file

@ -25,13 +25,9 @@ fn unsupported_zip_error<T>(detail: &str) -> IoResult<T>
impl<T: Reader+Seek> ZipReader<T> impl<T: Reader+Seek> ZipReader<T>
{ {
pub fn new(inner: T) -> IoResult<ZipReader<T>> pub fn new(mut reader: T) -> IoResult<ZipReader<T>>
{ {
let mut result = ZipReader { inner: RefCell::new(inner), files: Vec::new() }; let footer = try!(spec::CentralDirectoryEnd::find_and_parse(&mut reader));
{
let reader = &mut *result.inner.borrow_mut();
let footer = try!(spec::CentralDirectoryEnd::find_and_parse(reader));
if footer.number_of_disks > 1 { return unsupported_zip_error("Support for multi-disk files is not implemented") } if footer.number_of_disks > 1 { return unsupported_zip_error("Support for multi-disk files is not implemented") }
@ -43,13 +39,10 @@ impl<T: Reader+Seek> ZipReader<T>
try!(reader.seek(directory_start, io::SeekSet)); try!(reader.seek(directory_start, io::SeekSet));
for i in range(0, number_of_files) for i in range(0, number_of_files)
{ {
files.push(try!(ZipReader::parse_directory(reader))); files.push(try!(ZipReader::parse_directory(&mut reader)));
} }
result.files = files; Ok(ZipReader { inner: RefCell::new(reader), files: files })
}
Ok(result)
} }
fn parse_directory(reader: &mut T) -> IoResult<ZipFile> fn parse_directory(reader: &mut T) -> IoResult<ZipFile>