Fixed int/uint, and use as much stable as possible
This commit is contained in:
parent
b4f04ab79b
commit
70532d7b48
6 changed files with 21 additions and 20 deletions
|
@ -55,7 +55,7 @@ pub fn update(prev: u32, buf: &[u8]) -> u32
|
||||||
|
|
||||||
for byte in buf.iter()
|
for byte in buf.iter()
|
||||||
{
|
{
|
||||||
crc = CRC32_TABLE[((crc ^ (*byte as u32)) & 0xFF) as uint] ^ (crc >> 8);
|
crc = CRC32_TABLE[((crc ^ (*byte as u32)) & 0xFF) as usize] ^ (crc >> 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
return crc ^ !0u32;
|
return crc ^ !0u32;
|
||||||
|
@ -90,7 +90,7 @@ 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<uint>
|
fn read(&mut self, buf: &mut [u8]) -> io::IoResult<usize>
|
||||||
{
|
{
|
||||||
let count = match self.inner.read(buf)
|
let count = match self.inner.read(buf)
|
||||||
{
|
{
|
||||||
|
@ -103,7 +103,7 @@ impl<R: Reader> Reader for Crc32Reader<R>
|
||||||
},
|
},
|
||||||
Err(e) => return Err(e),
|
Err(e) => return Err(e),
|
||||||
};
|
};
|
||||||
self.crc = update(self.crc, buf.slice_to(count));
|
self.crc = update(self.crc, &buf[0..count]);
|
||||||
Ok(count)
|
Ok(count)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#![feature(unsafe_destructor)]
|
#![feature(unsafe_destructor)]
|
||||||
#![warn(missing_docs)]
|
#![warn(missing_docs)]
|
||||||
|
#![allow(unstable)]
|
||||||
|
|
||||||
#[macro_use] extern crate log;
|
#[macro_use] extern crate log;
|
||||||
extern crate time;
|
extern crate time;
|
||||||
|
|
|
@ -38,7 +38,7 @@ pub struct ZipReader<T>
|
||||||
{
|
{
|
||||||
inner: RefCell<T>,
|
inner: RefCell<T>,
|
||||||
files: Vec<ZipFile>,
|
files: Vec<ZipFile>,
|
||||||
names_map: HashMap<String, uint>,
|
names_map: HashMap<String, usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unsupported_zip_error<T>(detail: &'static str) -> ZipResult<T>
|
fn unsupported_zip_error<T>(detail: &'static str) -> ZipResult<T>
|
||||||
|
@ -56,13 +56,13 @@ impl<T: Reader+Seek> ZipReader<T>
|
||||||
if footer.disk_number != footer.disk_with_central_directory { return unsupported_zip_error("Support for multi-disk files is not implemented") }
|
if footer.disk_number != footer.disk_with_central_directory { return unsupported_zip_error("Support for multi-disk files is not implemented") }
|
||||||
|
|
||||||
let directory_start = footer.central_directory_offset as i64;
|
let directory_start = footer.central_directory_offset as i64;
|
||||||
let number_of_files = footer.number_of_files_on_this_disk as uint;
|
let number_of_files = footer.number_of_files_on_this_disk as usize;
|
||||||
|
|
||||||
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, io::SeekSet));
|
||||||
for _ in range(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));
|
||||||
names_map.insert(file.file_name.clone(), files.len());
|
names_map.insert(file.file_name.clone(), files.len());
|
||||||
|
@ -75,7 +75,7 @@ impl<T: Reader+Seek> ZipReader<T>
|
||||||
/// An iterator over the information of all contained files.
|
/// An iterator over the information of all contained files.
|
||||||
pub fn files(&self) -> ::std::slice::Iter<ZipFile>
|
pub fn files(&self) -> ::std::slice::Iter<ZipFile>
|
||||||
{
|
{
|
||||||
self.files.as_slice().iter()
|
(&*self.files).iter()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Search for a file entry by name
|
/// Search for a file entry by name
|
||||||
|
@ -103,7 +103,7 @@ impl<T: Reader+Seek> ZipReader<T>
|
||||||
|
|
||||||
try!(inner_reader.seek(pos, io::SeekSet));
|
try!(inner_reader.seek(pos, 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 uint);
|
let limit_reader = io::util::LimitReader::new(refmut_reader, file.compressed_size as usize);
|
||||||
|
|
||||||
let reader = match file.compression_method
|
let reader = match file.compression_method
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,9 +26,9 @@ pub fn central_header_to_zip_file<R: Reader+Seek>(reader: &mut R) -> ZipResult<Z
|
||||||
let crc32 = try!(reader.read_le_u32());
|
let crc32 = try!(reader.read_le_u32());
|
||||||
let compressed_size = try!(reader.read_le_u32());
|
let compressed_size = try!(reader.read_le_u32());
|
||||||
let uncompressed_size = try!(reader.read_le_u32());
|
let uncompressed_size = try!(reader.read_le_u32());
|
||||||
let file_name_length = try!(reader.read_le_u16()) as uint;
|
let file_name_length = try!(reader.read_le_u16()) as usize;
|
||||||
let extra_field_length = try!(reader.read_le_u16()) as uint;
|
let extra_field_length = try!(reader.read_le_u16()) as usize;
|
||||||
let file_comment_length = try!(reader.read_le_u16()) as uint;
|
let file_comment_length = try!(reader.read_le_u16()) as usize;
|
||||||
try!(reader.read_le_u16());
|
try!(reader.read_le_u16());
|
||||||
try!(reader.read_le_u16());
|
try!(reader.read_le_u16());
|
||||||
try!(reader.read_le_u32());
|
try!(reader.read_le_u32());
|
||||||
|
@ -39,13 +39,13 @@ pub fn central_header_to_zip_file<R: Reader+Seek>(reader: &mut R) -> ZipResult<Z
|
||||||
|
|
||||||
let file_name = match is_utf8
|
let file_name = match is_utf8
|
||||||
{
|
{
|
||||||
true => String::from_utf8_lossy(file_name_raw.as_slice()).into_owned(),
|
true => String::from_utf8_lossy(&*file_name_raw).into_owned(),
|
||||||
false => ::cp437::to_string(file_name_raw.as_slice()),
|
false => ::cp437::to_string(&*file_name_raw),
|
||||||
};
|
};
|
||||||
let file_comment = match is_utf8
|
let file_comment = match is_utf8
|
||||||
{
|
{
|
||||||
true => String::from_utf8_lossy(file_comment_raw.as_slice()).into_owned(),
|
true => String::from_utf8_lossy(&*file_comment_raw).into_owned(),
|
||||||
false => ::cp437::to_string(file_comment_raw.as_slice()),
|
false => ::cp437::to_string(&*file_comment_raw),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Remember end of central header
|
// Remember end of central header
|
||||||
|
@ -80,7 +80,7 @@ pub fn central_header_to_zip_file<R: Reader+Seek>(reader: &mut R) -> ZipResult<Z
|
||||||
data_start: data_start,
|
data_start: data_start,
|
||||||
};
|
};
|
||||||
|
|
||||||
try!(parse_extra_field(&mut result, extra_field.as_slice()));
|
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, io::SeekSet));
|
||||||
|
|
|
@ -32,7 +32,7 @@ impl CentralDirectoryEnd
|
||||||
let number_of_files = try!(reader.read_le_u16());
|
let number_of_files = try!(reader.read_le_u16());
|
||||||
let central_directory_size = try!(reader.read_le_u32());
|
let central_directory_size = try!(reader.read_le_u32());
|
||||||
let central_directory_offset = try!(reader.read_le_u32());
|
let central_directory_offset = try!(reader.read_le_u32());
|
||||||
let zip_file_comment_length = try!(reader.read_le_u16()) as uint;
|
let zip_file_comment_length = try!(reader.read_le_u16()) as usize;
|
||||||
let zip_file_comment = try!(reader.read_exact(zip_file_comment_length));
|
let zip_file_comment = try!(reader.read_exact(zip_file_comment_length));
|
||||||
|
|
||||||
Ok(CentralDirectoryEnd
|
Ok(CentralDirectoryEnd
|
||||||
|
|
|
@ -12,7 +12,7 @@ pub fn msdos_datetime_to_tm(time: u16, date: u16) -> Tm
|
||||||
let years = (date & 0b1111111000000000) >> 9;
|
let years = (date & 0b1111111000000000) >> 9;
|
||||||
|
|
||||||
let datetime = format!("{:04}-{:02}-{:02} {:02}:{:02}:{:02}",
|
let datetime = format!("{:04}-{:02}-{:02} {:02}:{:02}:{:02}",
|
||||||
years as uint + 1980,
|
years as u32 + 1980,
|
||||||
months,
|
months,
|
||||||
days,
|
days,
|
||||||
hours,
|
hours,
|
||||||
|
@ -20,7 +20,7 @@ pub fn msdos_datetime_to_tm(time: u16, date: u16) -> Tm
|
||||||
seconds);
|
seconds);
|
||||||
let format = "%Y-%m-%d %H:%M:%S";
|
let format = "%Y-%m-%d %H:%M:%S";
|
||||||
|
|
||||||
match time::strptime(datetime.as_slice(), format)
|
match time::strptime(&*datetime, format)
|
||||||
{
|
{
|
||||||
Ok(tm) => tm,
|
Ok(tm) => tm,
|
||||||
Err(m) => { debug!("Failed parsing date: {}", m); time::empty_tm() },
|
Err(m) => { debug!("Failed parsing date: {}", m); time::empty_tm() },
|
||||||
|
@ -52,7 +52,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<uint>
|
fn read(&mut self, buf: &mut [u8]) -> ::std::io::IoResult<usize>
|
||||||
{
|
{
|
||||||
self.inner.read(buf)
|
self.inner.read(buf)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue