Struct zip::read::ZipArchive
source · [−]pub struct ZipArchive<R> { /* private fields */ }
Expand description
ZIP archive reader
use std::io::prelude::*;
fn list_zip_contents(reader: impl Read + Seek) -> zip::result::ZipResult<()> {
let mut zip = zip::ZipArchive::new(reader)?;
for i in 0..zip.len() {
let mut file = zip.by_index(i)?;
println!("Filename: {}", file.name());
std::io::copy(&mut file, &mut std::io::stdout());
}
Ok(())
}
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>>
Read a ZIP archive, collecting the files it contains
This uses the central directory record of the ZIP file, and ignores local file headers
sourcepub fn extract<P: AsRef<Path>>(&mut self, directory: P) -> ZipResult<()>
pub fn extract<P: AsRef<Path>>(&mut self, directory: P) -> ZipResult<()>
Extract a Zip archive into a directory, overwriting files if they
already exist. Paths are sanitized with ZipFile::enclosed_name
.
Extraction is not atomic; If an error is encountered, some of the files may be left on disk.
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 comment(&self) -> &[u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
pub fn comment(&self) -> &[u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
Get the comment of the zip archive.
sourcepub fn file_names(&self) -> impl Iterator<Item = &str>
pub fn file_names(&self) -> impl Iterator<Item = &str>
Returns an iterator over all the file and directory names in this archive.
sourcepub fn by_name_decrypt<'a>(
&'a mut self,
name: &str,
password: &[u8]
) -> ZipResult<Result<ZipFile<'a>, InvalidPassword>>
pub fn by_name_decrypt<'a>(
&'a mut self,
name: &str,
password: &[u8]
) -> ZipResult<Result<ZipFile<'a>, InvalidPassword>>
Search for a file entry by name, decrypt with given password
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_decrypt<'a>(
&'a mut self,
file_number: usize,
password: &[u8]
) -> ZipResult<Result<ZipFile<'a>, InvalidPassword>>
pub fn by_index_decrypt<'a>(
&'a mut self,
file_number: usize,
password: &[u8]
) -> ZipResult<Result<ZipFile<'a>, InvalidPassword>>
Get a contained file by index, decrypt with given password
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 by_index_raw<'a>(
&'a mut self,
file_number: usize
) -> ZipResult<ZipFile<'a>>
pub fn by_index_raw<'a>(
&'a mut self,
file_number: usize
) -> ZipResult<ZipFile<'a>>
Get a contained file by index without decompressing it
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> Clone for ZipArchive<R>
impl<R: Clone> 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 more
Auto 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 T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
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