Struct zip::read::ZipArchive

source ·
pub struct ZipArchive<R: Read + Seek> { /* private fields */ }
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

Opens a Zip archive and parses the central directory

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
    }
}

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.

Search for a file entry by name

Get a contained file by index

Unwrap and return the inner reader object

The position of the reader is undefined.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.