Struct zip::read::ZipArchive

source ·
pub struct ZipArchive<R> { /* private fields */ }
Expand description

ZIP archive reader

At the moment, this type is cheap to clone if this is the case for the reader it uses. However, this is not guaranteed by this crate and it may change in the future.

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§

source§

impl<R: Read + Seek> ZipArchive<R>

source

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

source

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.

source

pub fn len(&self) -> usize

Number of files contained in this zip.

source

pub fn is_empty(&self) -> bool

Whether this zip archive contains no files

source

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.

source

pub fn comment(&self) -> &[u8]

Get the comment of the zip archive.

source

pub fn file_names(&self) -> impl Iterator<Item = &str>

Returns an iterator over all the file and directory names in this archive.

source

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

Warning

The implementation of the cryptographic algorithms has not gone through a correctness review, and you should assume it is insecure: passwords used with this API may be compromised.

This function sometimes accepts wrong password. This is because the ZIP spec only allows us to check for a 1/256 chance that the password is correct. There are many passwords out there that will also pass the validity checks we are able to perform. This is a weakness of the ZipCrypto algorithm, due to its fairly primitive approach to cryptography.

source

pub fn by_name<'a>(&'a mut self, name: &str) -> ZipResult<ZipFile<'a>>

Search for a file entry by name

source

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

Warning

The implementation of the cryptographic algorithms has not gone through a correctness review, and you should assume it is insecure: passwords used with this API may be compromised.

This function sometimes accepts wrong password. This is because the ZIP spec only allows us to check for a 1/256 chance that the password is correct. There are many passwords out there that will also pass the validity checks we are able to perform. This is a weakness of the ZipCrypto algorithm, due to its fairly primitive approach to cryptography.

source

pub fn by_index(&mut self, file_number: usize) -> ZipResult<ZipFile<'_>>

Get a contained file by index

source

pub fn by_index_raw(&mut self, file_number: usize) -> ZipResult<ZipFile<'_>>

Get a contained file by index without decompressing it

source

pub fn into_inner(self) -> R

Unwrap and return the inner reader object

The position of the reader is undefined.

Trait Implementations§

source§

impl<R: Clone> Clone for ZipArchive<R>

source§

fn clone(&self) -> ZipArchive<R>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<R: Debug> Debug for ZipArchive<R>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.