Struct zip::read::ZipArchive
source · Expand description
Wrapper for reading the contents of a ZIP file.
fn doit() -> zip::result::ZipResult<()>
{
use std::io::prelude::*;
// For demonstration purposes we read from an empty buffer.
// Normally a File object would be used.
let buf: &[u8] = &[0u8; 128];
let mut reader = std::io::Cursor::new(buf);
let mut zip = zip::ZipArchive::new(reader)?;
for i in 0..zip.len()
{
let mut file = zip.by_index(i).unwrap();
println!("Filename: {}", file.name());
let first_byte = file.bytes().next().unwrap()?;
println!("{}", first_byte);
}
Ok(())
}
println!("Result: {:?}", doit());
Implementations
sourceimpl<R: Read + Seek> ZipArchive<R>
impl<R: Read + Seek> ZipArchive<R>
sourcepub fn new(reader: R) -> ZipResult<ZipArchive<R>>
pub fn new(reader: R) -> ZipResult<ZipArchive<R>>
Opens a Zip archive and parses the central directory
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Number of files contained in this zip.
fn iter() {
let mut zip = zip::ZipArchive::new(std::io::Cursor::new(vec![])).unwrap();
for i in 0..zip.len() {
let mut file = zip.by_index(i).unwrap();
// Do something with file i
}
}
sourcepub fn offset(&self) -> u64
pub fn offset(&self) -> u64
Get the offset from the beginning of the underlying reader that this zip begins at, in bytes.
Normally this value is zero, but if the zip has arbitrary data prepended to it, then this value will be the size of that prepended data.
sourcepub fn by_name<'a>(&'a mut self, name: &str) -> ZipResult<ZipFile<'a>>
pub fn by_name<'a>(&'a mut self, name: &str) -> ZipResult<ZipFile<'a>>
Search for a file entry by name
sourcepub fn by_index<'a>(&'a mut self, file_number: usize) -> ZipResult<ZipFile<'a>>
pub fn by_index<'a>(&'a mut self, file_number: usize) -> ZipResult<ZipFile<'a>>
Get a contained file by index
sourcepub fn into_inner(self) -> R
pub fn into_inner(self) -> R
Unwrap and return the inner reader object
The position of the reader is undefined.
Trait Implementations
sourceimpl<R: Clone + Read + Seek> Clone for ZipArchive<R>
impl<R: Clone + Read + Seek> Clone for ZipArchive<R>
sourcefn clone(&self) -> ZipArchive<R>
fn clone(&self) -> ZipArchive<R>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations
impl<R> RefUnwindSafe for ZipArchive<R>where
R: RefUnwindSafe,
impl<R> Send for ZipArchive<R>where
R: Send,
impl<R> Sync for ZipArchive<R>where
R: Sync,
impl<R> Unpin for ZipArchive<R>where
R: Unpin,
impl<R> UnwindSafe for ZipArchive<R>where
R: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more