io -> old_io
This commit is contained in:
parent
b88abe1582
commit
078ba7eda0
8 changed files with 35 additions and 35 deletions
|
@ -1,6 +1,6 @@
|
||||||
//! Helper module to compute a CRC32 checksum
|
//! Helper module to compute a CRC32 checksum
|
||||||
|
|
||||||
use std::io;
|
use std::old_io;
|
||||||
|
|
||||||
static CRC32_TABLE : [u32; 256] = [
|
static CRC32_TABLE : [u32; 256] = [
|
||||||
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
|
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
|
||||||
|
@ -90,16 +90,16 @@ impl<R: Reader> Crc32Reader<R>
|
||||||
|
|
||||||
impl<R: Reader> Reader for Crc32Reader<R>
|
impl<R: Reader> Reader for Crc32Reader<R>
|
||||||
{
|
{
|
||||||
fn read(&mut self, buf: &mut [u8]) -> io::IoResult<usize>
|
fn read(&mut self, buf: &mut [u8]) -> old_io::IoResult<usize>
|
||||||
{
|
{
|
||||||
let count = match self.inner.read(buf)
|
let count = match self.inner.read(buf)
|
||||||
{
|
{
|
||||||
Ok(n) => n,
|
Ok(n) => n,
|
||||||
Err(ref e) if e.kind == io::EndOfFile =>
|
Err(ref e) if e.kind == old_io::EndOfFile =>
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
if self.check_matches() { Err(e.clone()) }
|
if self.check_matches() { Err(e.clone()) }
|
||||||
else { Err(io::IoError { kind: io::OtherIoError, desc: "Invalid checksum", detail: None, }) }
|
else { Err(old_io::IoError { kind: old_io::OtherIoError, desc: "Invalid checksum", detail: None, }) }
|
||||||
},
|
},
|
||||||
Err(e) => return Err(e),
|
Err(e) => return Err(e),
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,7 +4,7 @@ use compression::CompressionMethod;
|
||||||
use spec;
|
use spec;
|
||||||
use reader_spec;
|
use reader_spec;
|
||||||
use result::{ZipResult, ZipError};
|
use result::{ZipResult, ZipError};
|
||||||
use std::io;
|
use std::old_io;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use flate2::FlateReader;
|
use flate2::FlateReader;
|
||||||
|
@ -61,7 +61,7 @@ impl<T: Reader+Seek> ZipReader<T>
|
||||||
let mut files = Vec::with_capacity(number_of_files);
|
let mut files = Vec::with_capacity(number_of_files);
|
||||||
let mut names_map = HashMap::new();
|
let mut names_map = HashMap::new();
|
||||||
|
|
||||||
try!(reader.seek(directory_start, io::SeekSet));
|
try!(reader.seek(directory_start, old_io::SeekSet));
|
||||||
for _ in (0 .. number_of_files)
|
for _ in (0 .. number_of_files)
|
||||||
{
|
{
|
||||||
let file = try!(reader_spec::central_header_to_zip_file(&mut reader));
|
let file = try!(reader_spec::central_header_to_zip_file(&mut reader));
|
||||||
|
@ -101,9 +101,9 @@ impl<T: Reader+Seek> ZipReader<T>
|
||||||
return unsupported_zip_error("Encrypted files are not supported")
|
return unsupported_zip_error("Encrypted files are not supported")
|
||||||
}
|
}
|
||||||
|
|
||||||
try!(inner_reader.seek(pos, io::SeekSet));
|
try!(inner_reader.seek(pos, old_io::SeekSet));
|
||||||
let refmut_reader = ::util::RefMutReader::new(inner_reader);
|
let refmut_reader = ::util::RefMutReader::new(inner_reader);
|
||||||
let limit_reader = io::util::LimitReader::new(refmut_reader, file.compressed_size as usize);
|
let limit_reader = old_io::util::LimitReader::new(refmut_reader, file.compressed_size as usize);
|
||||||
|
|
||||||
let reader = match file.compression_method
|
let reader = match file.compression_method
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::io;
|
use std::old_io;
|
||||||
use std::num::FromPrimitive;
|
use std::num::FromPrimitive;
|
||||||
use result::{ZipResult, ZipError};
|
use result::{ZipResult, ZipError};
|
||||||
use types::ZipFile;
|
use types::ZipFile;
|
||||||
|
@ -52,14 +52,14 @@ pub fn central_header_to_zip_file<R: Reader+Seek>(reader: &mut R) -> ZipResult<Z
|
||||||
let return_position = try!(reader.tell()) as i64;
|
let return_position = try!(reader.tell()) as i64;
|
||||||
|
|
||||||
// Parse local header
|
// Parse local header
|
||||||
try!(reader.seek(offset, io::SeekSet));
|
try!(reader.seek(offset, old_io::SeekSet));
|
||||||
let signature = try!(reader.read_le_u32());
|
let signature = try!(reader.read_le_u32());
|
||||||
if signature != spec::LOCAL_FILE_HEADER_SIGNATURE
|
if signature != spec::LOCAL_FILE_HEADER_SIGNATURE
|
||||||
{
|
{
|
||||||
return Err(ZipError::InvalidZipFile("Invalid local file header"))
|
return Err(ZipError::InvalidZipFile("Invalid local file header"))
|
||||||
}
|
}
|
||||||
|
|
||||||
try!(reader.seek(22, io::SeekCur));
|
try!(reader.seek(22, old_io::SeekCur));
|
||||||
let file_name_length = try!(reader.read_le_u16()) as u64;
|
let file_name_length = try!(reader.read_le_u16()) as u64;
|
||||||
let extra_field_length = try!(reader.read_le_u16()) as u64;
|
let extra_field_length = try!(reader.read_le_u16()) as u64;
|
||||||
let magic_and_header = 4 + 22 + 2 + 2;
|
let magic_and_header = 4 + 22 + 2 + 2;
|
||||||
|
@ -83,21 +83,21 @@ pub fn central_header_to_zip_file<R: Reader+Seek>(reader: &mut R) -> ZipResult<Z
|
||||||
try!(parse_extra_field(&mut result, &*extra_field));
|
try!(parse_extra_field(&mut result, &*extra_field));
|
||||||
|
|
||||||
// Go back after the central header
|
// Go back after the central header
|
||||||
try!(reader.seek(return_position, io::SeekSet));
|
try!(reader.seek(return_position, old_io::SeekSet));
|
||||||
|
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_extra_field(_file: &mut ZipFile, data: &[u8]) -> ZipResult<()>
|
fn parse_extra_field(_file: &mut ZipFile, data: &[u8]) -> ZipResult<()>
|
||||||
{
|
{
|
||||||
let mut reader = io::BufReader::new(data);
|
let mut reader = old_io::BufReader::new(data);
|
||||||
while !reader.eof()
|
while !reader.eof()
|
||||||
{
|
{
|
||||||
let kind = try!(reader.read_le_u16());
|
let kind = try!(reader.read_le_u16());
|
||||||
let len = try!(reader.read_le_u16());
|
let len = try!(reader.read_le_u16());
|
||||||
match kind
|
match kind
|
||||||
{
|
{
|
||||||
_ => try!(reader.seek(len as i64, io::SeekCur)),
|
_ => try!(reader.seek(len as i64, old_io::SeekCur)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//! Error types that can be emitted from this library
|
//! Error types that can be emitted from this library
|
||||||
|
|
||||||
use std::io;
|
use std::old_io::IoError;
|
||||||
use std::error;
|
use std::error;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ pub type ZipResult<T> = Result<T, ZipError>;
|
||||||
pub enum ZipError
|
pub enum ZipError
|
||||||
{
|
{
|
||||||
/// An Error caused by I/O
|
/// An Error caused by I/O
|
||||||
Io(io::IoError),
|
Io(IoError),
|
||||||
|
|
||||||
/// This file is probably not a zipfile. The argument is enclosed.
|
/// This file is probably not a zipfile. The argument is enclosed.
|
||||||
InvalidZipFile(&'static str),
|
InvalidZipFile(&'static str),
|
||||||
|
@ -46,9 +46,9 @@ impl ZipError
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl error::FromError<io::IoError> for ZipError
|
impl error::FromError<IoError> for ZipError
|
||||||
{
|
{
|
||||||
fn from_error(err: io::IoError) -> ZipError
|
fn from_error(err: IoError) -> ZipError
|
||||||
{
|
{
|
||||||
ZipError::Io(err)
|
ZipError::Io(err)
|
||||||
}
|
}
|
||||||
|
|
10
src/spec.rs
10
src/spec.rs
|
@ -1,4 +1,4 @@
|
||||||
use std::io;
|
use std::old_io;
|
||||||
use result::{ZipResult, ZipError};
|
use result::{ZipResult, ZipError};
|
||||||
use std::iter::range_step_inclusive;
|
use std::iter::range_step_inclusive;
|
||||||
|
|
||||||
|
@ -51,20 +51,20 @@ impl CentralDirectoryEnd
|
||||||
{
|
{
|
||||||
let header_size = 22;
|
let header_size = 22;
|
||||||
let bytes_between_magic_and_comment_size = header_size - 6;
|
let bytes_between_magic_and_comment_size = header_size - 6;
|
||||||
try!(reader.seek(0, io::SeekEnd));
|
try!(reader.seek(0, old_io::SeekEnd));
|
||||||
let file_length = try!(reader.tell()) as i64;
|
let file_length = try!(reader.tell()) as i64;
|
||||||
|
|
||||||
let search_upper_bound = ::std::cmp::max(0, file_length - header_size - ::std::u16::MAX as i64);
|
let search_upper_bound = ::std::cmp::max(0, file_length - header_size - ::std::u16::MAX as i64);
|
||||||
for pos in range_step_inclusive(file_length - header_size, search_upper_bound, -1)
|
for pos in range_step_inclusive(file_length - header_size, search_upper_bound, -1)
|
||||||
{
|
{
|
||||||
try!(reader.seek(pos, io::SeekSet));
|
try!(reader.seek(pos, old_io::SeekSet));
|
||||||
if try!(reader.read_le_u32()) == CENTRAL_DIRECTORY_END_SIGNATURE
|
if try!(reader.read_le_u32()) == CENTRAL_DIRECTORY_END_SIGNATURE
|
||||||
{
|
{
|
||||||
try!(reader.seek(bytes_between_magic_and_comment_size, io::SeekCur));
|
try!(reader.seek(bytes_between_magic_and_comment_size, old_io::SeekCur));
|
||||||
let comment_length = try!(reader.read_le_u16()) as i64;
|
let comment_length = try!(reader.read_le_u16()) as i64;
|
||||||
if file_length - pos - header_size == comment_length
|
if file_length - pos - header_size == comment_length
|
||||||
{
|
{
|
||||||
try!(reader.seek(pos, io::SeekSet));
|
try!(reader.seek(pos, old_io::SeekSet));
|
||||||
return CentralDirectoryEnd::parse(reader);
|
return CentralDirectoryEnd::parse(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ pub fn msdos_datetime_to_tm(time: u16, date: u16) -> Tm
|
||||||
{
|
{
|
||||||
Ok(tm) => tm,
|
Ok(tm) => tm,
|
||||||
Err(m) => {
|
Err(m) => {
|
||||||
let _ = write!(&mut ::std::io::stdio::stderr(), "Failed parsing date: {}", m);
|
let _ = write!(&mut ::std::old_io::stdio::stderr(), "Failed parsing date: {}", m);
|
||||||
time::empty_tm()
|
time::empty_tm()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ impl<'a, R: Reader> RefMutReader<'a, R>
|
||||||
|
|
||||||
impl<'a, R: Reader> Reader for RefMutReader<'a, R>
|
impl<'a, R: Reader> Reader for RefMutReader<'a, R>
|
||||||
{
|
{
|
||||||
fn read(&mut self, buf: &mut [u8]) -> ::std::io::IoResult<usize>
|
fn read(&mut self, buf: &mut [u8]) -> ::std::old_io::IoResult<usize>
|
||||||
{
|
{
|
||||||
self.inner.read(buf)
|
self.inner.read(buf)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ use writer_spec;
|
||||||
use crc32;
|
use crc32;
|
||||||
use result::{ZipResult, ZipError};
|
use result::{ZipResult, ZipError};
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use std::io;
|
use std::old_io;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use time;
|
use time;
|
||||||
use flate2;
|
use flate2;
|
||||||
|
@ -60,16 +60,16 @@ struct ZipWriterStats
|
||||||
|
|
||||||
impl<W: Writer+Seek> Writer for ZipWriter<W>
|
impl<W: Writer+Seek> Writer for ZipWriter<W>
|
||||||
{
|
{
|
||||||
fn write(&mut self, buf: &[u8]) -> io::IoResult<()>
|
fn write(&mut self, buf: &[u8]) -> old_io::IoResult<()>
|
||||||
{
|
{
|
||||||
if self.files.len() == 0 { return Err(io::IoError { kind: io::OtherIoError, desc: "No file has been started", detail: None, }) }
|
if self.files.len() == 0 { return Err(old_io::IoError { kind: old_io::OtherIoError, desc: "No file has been started", detail: None, }) }
|
||||||
self.stats.update(buf);
|
self.stats.update(buf);
|
||||||
match self.inner
|
match self.inner
|
||||||
{
|
{
|
||||||
GenericZipWriter::Storer(ref mut w) => w.write(buf),
|
GenericZipWriter::Storer(ref mut w) => w.write(buf),
|
||||||
GenericZipWriter::Deflater(ref mut w) => w.write(buf),
|
GenericZipWriter::Deflater(ref mut w) => w.write(buf),
|
||||||
GenericZipWriter::Bzip2(ref mut w) => w.write(buf),
|
GenericZipWriter::Bzip2(ref mut w) => w.write(buf),
|
||||||
GenericZipWriter::Closed => Err(io::standard_error(io::Closed)),
|
GenericZipWriter::Closed => Err(old_io::standard_error(old_io::Closed)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,7 +152,7 @@ impl<W: Writer+Seek> ZipWriter<W>
|
||||||
file.compressed_size = try!(writer.tell()) - self.stats.start;
|
file.compressed_size = try!(writer.tell()) - self.stats.start;
|
||||||
|
|
||||||
try!(writer_spec::update_local_file_header(writer, file));
|
try!(writer_spec::update_local_file_header(writer, file));
|
||||||
try!(writer.seek(0, io::SeekEnd));
|
try!(writer.seek(0, old_io::SeekEnd));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,7 +207,7 @@ impl<W: Writer+Seek> Drop for ZipWriter<W>
|
||||||
if !self.inner.is_closed()
|
if !self.inner.is_closed()
|
||||||
{
|
{
|
||||||
if let Err(e) = self.finalize() {
|
if let Err(e) = self.finalize() {
|
||||||
let _ = write!(&mut ::std::io::stdio::stderr(), "ZipWriter drop failed: {:?}", e);
|
let _ = write!(&mut old_io::stdio::stderr(), "ZipWriter drop failed: {:?}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -222,7 +222,7 @@ impl<W: Writer+Seek> GenericZipWriter<W>
|
||||||
GenericZipWriter::Storer(w) => w,
|
GenericZipWriter::Storer(w) => w,
|
||||||
GenericZipWriter::Deflater(w) => try!(w.finish()),
|
GenericZipWriter::Deflater(w) => try!(w.finish()),
|
||||||
GenericZipWriter::Bzip2(w) => match w.into_inner() { Ok(r) => r, 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::standard_error(io::Closed))),
|
GenericZipWriter::Closed => try!(Err(old_io::standard_error(old_io::Closed))),
|
||||||
};
|
};
|
||||||
|
|
||||||
*self = match compression
|
*self = match compression
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::io;
|
use std::old_io;
|
||||||
use std::ascii::AsciiExt;
|
use std::ascii::AsciiExt;
|
||||||
use types::ZipFile;
|
use types::ZipFile;
|
||||||
use result::ZipResult;
|
use result::ZipResult;
|
||||||
|
@ -29,7 +29,7 @@ pub fn write_local_file_header<T: Writer>(writer: &mut T, file: &ZipFile) -> Zip
|
||||||
pub fn update_local_file_header<T: Writer+Seek>(writer: &mut T, file: &ZipFile) -> ZipResult<()>
|
pub fn update_local_file_header<T: Writer+Seek>(writer: &mut T, file: &ZipFile) -> ZipResult<()>
|
||||||
{
|
{
|
||||||
static CRC32_OFFSET : i64 = 14;
|
static CRC32_OFFSET : i64 = 14;
|
||||||
try!(writer.seek(file.header_start as i64 + CRC32_OFFSET, io::SeekSet));
|
try!(writer.seek(file.header_start as i64 + CRC32_OFFSET, old_io::SeekSet));
|
||||||
try!(writer.write_le_u32(file.crc32));
|
try!(writer.write_le_u32(file.crc32));
|
||||||
try!(writer.write_le_u32(file.compressed_size as u32));
|
try!(writer.write_le_u32(file.compressed_size as u32));
|
||||||
try!(writer.write_le_u32(file.uncompressed_size as u32));
|
try!(writer.write_le_u32(file.uncompressed_size as u32));
|
||||||
|
@ -65,7 +65,7 @@ pub fn write_central_directory_header<T: Writer>(writer: &mut T, file: &ZipFile)
|
||||||
|
|
||||||
fn build_extra_field(_file: &ZipFile) -> ZipResult<Vec<u8>>
|
fn build_extra_field(_file: &ZipFile) -> ZipResult<Vec<u8>>
|
||||||
{
|
{
|
||||||
let writer = io::MemWriter::new();
|
let writer = old_io::MemWriter::new();
|
||||||
// Future work
|
// Future work
|
||||||
Ok(writer.into_inner())
|
Ok(writer.into_inner())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue