Fixed borrowing issue in extract
This commit is contained in:
parent
3befdf5594
commit
bb4f56346a
3 changed files with 16 additions and 13 deletions
|
@ -7,9 +7,10 @@ fn main()
|
||||||
let file = std::io::File::open(&fname);
|
let file = std::io::File::open(&fname);
|
||||||
|
|
||||||
let mut zipcontainer = zip::reader::ZipContainer::new(file).unwrap();
|
let mut zipcontainer = zip::reader::ZipContainer::new(file).unwrap();
|
||||||
|
|
||||||
for i in zipcontainer.files()
|
for i in zipcontainer.files()
|
||||||
{
|
{
|
||||||
println!("File: {}", String::from_utf8_lossy(i.name.as_slice()));
|
println!("{}", String::from_utf8_lossy(i.name.as_slice()));
|
||||||
|
|
||||||
if i.size == 0 { continue }
|
if i.size == 0 { continue }
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ pub struct ZipContainer<T>
|
||||||
files: Vec<ZipFile>,
|
files: Vec<ZipFile>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[deriving(Clone)]
|
||||||
struct ZipFile
|
struct ZipFile
|
||||||
{
|
{
|
||||||
central_header: spec::CentralDirectoryHeader,
|
central_header: spec::CentralDirectoryHeader,
|
||||||
|
@ -17,9 +18,9 @@ struct ZipFile
|
||||||
_data_descriptor: Option<spec::DataDescriptor>,
|
_data_descriptor: Option<spec::DataDescriptor>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ZipFileItems<'a, T:'a>
|
pub struct ZipFileItems
|
||||||
{
|
{
|
||||||
container: &'a ZipContainer<T>,
|
list: Vec<ZipFile>,
|
||||||
pos: uint,
|
pos: uint,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,9 +74,9 @@ impl<T: Reader+Seek> ZipContainer<T>
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn files(&mut self) -> ZipFileItems<T>
|
pub fn files(&self) -> ZipFileItems
|
||||||
{
|
{
|
||||||
ZipFileItems { container: self, pos: 0 }
|
ZipFileItems { list: self.files.clone(), pos: 0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_file(&mut self, item: &ZipFileItem) -> IoResult<Box<Reader>>
|
pub fn read_file(&mut self, item: &ZipFileItem) -> IoResult<Box<Reader>>
|
||||||
|
@ -117,9 +118,9 @@ impl ZipFile
|
||||||
|
|
||||||
impl ZipFileItem
|
impl ZipFileItem
|
||||||
{
|
{
|
||||||
fn new<T>(container: &ZipContainer<T>, index: uint) -> IoResult<ZipFileItem>
|
fn new(list: &Vec<ZipFile>, index: uint) -> IoResult<ZipFileItem>
|
||||||
{
|
{
|
||||||
let file = &container.files[index];
|
let file = &list[index];
|
||||||
|
|
||||||
let name = file.central_header.file_name.clone();
|
let name = file.central_header.file_name.clone();
|
||||||
|
|
||||||
|
@ -127,18 +128,18 @@ impl ZipFileItem
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T: Reader+Seek> Iterator<ZipFileItem> for ZipFileItems<'a, T>
|
impl Iterator<ZipFileItem> for ZipFileItems
|
||||||
{
|
{
|
||||||
fn next(&mut self) -> Option<ZipFileItem>
|
fn next(&mut self) -> Option<ZipFileItem>
|
||||||
{
|
{
|
||||||
self.pos += 1;
|
self.pos += 1;
|
||||||
if self.pos - 1 >= self.container.files.len()
|
if self.pos - 1 >= self.list.len()
|
||||||
{
|
{
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ZipFileItem::new(self.container, self.pos - 1).ok()
|
ZipFileItem::new(&self.list, self.pos - 1).ok()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ static DATA_DESCRIPTOR_SIGNATURE : u32 = 0x08074b50;
|
||||||
static CENTRAL_DIRECTORY_HEADER_SIGNATURE : u32 = 0x02014b50;
|
static CENTRAL_DIRECTORY_HEADER_SIGNATURE : u32 = 0x02014b50;
|
||||||
static CENTRAL_DIRECTORY_END_SIGNATURE : u32 = 0x06054b50;
|
static CENTRAL_DIRECTORY_END_SIGNATURE : u32 = 0x06054b50;
|
||||||
|
|
||||||
#[deriving(FromPrimitive, Show)]
|
#[deriving(FromPrimitive, Clone)]
|
||||||
pub enum CompressionMethod
|
pub enum CompressionMethod
|
||||||
{
|
{
|
||||||
Stored = 0,
|
Stored = 0,
|
||||||
|
@ -31,7 +31,7 @@ pub enum CompressionMethod
|
||||||
Unknown = 100000,
|
Unknown = 100000,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Show)]
|
#[deriving(Clone)]
|
||||||
pub struct LocalFileHeader
|
pub struct LocalFileHeader
|
||||||
{
|
{
|
||||||
pub extract_version: u16,
|
pub extract_version: u16,
|
||||||
|
@ -107,6 +107,7 @@ impl LocalFileHeader
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[deriving(Clone)]
|
||||||
pub struct DataDescriptor
|
pub struct DataDescriptor
|
||||||
{
|
{
|
||||||
pub compressed_size: u32,
|
pub compressed_size: u32,
|
||||||
|
@ -140,7 +141,7 @@ impl DataDescriptor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Show)]
|
#[deriving(Clone)]
|
||||||
pub struct CentralDirectoryHeader
|
pub struct CentralDirectoryHeader
|
||||||
{
|
{
|
||||||
pub made_by: u16,
|
pub made_by: u16,
|
||||||
|
|
Loading…
Add table
Reference in a new issue