Skip to main content

ZipArchive

Struct ZipArchive 

Source
pub struct ZipArchive<'a> { /* private fields */ }
Expand description

A ZIP archive to be read

Implementations§

Source§

impl<'a> ZipArchive<'a>

Source

pub fn new(mapping: &'a [u8]) -> ZipResult<Self>

Reads a ZIP archive from a byte slice. Smaller files can be read into a buffer.

let bytes = fs::read("foo.zip")?;
let archive = ZipArchive::new(&bytes)?;

For larger ones, memory map!

let zip_file = File::open("foo.zip")?;
let mapping = unsafe { Mmap::map(&zip_file)? };
let archive = ZipArchive::new(&mapping)?;
Source

pub fn with_prepended_data(mapping: &'a [u8]) -> ZipResult<(Self, usize)>

Like ZipArchive::new(), but allows arbitrary data to prepend the archive. Returns the ZipArchive and the number of bytes prepended to the archive.

Since a ZIP archive’s metadata sits at the back of the file, many formats consist of ZIP archives prepended with some other data. For example, a self-extracting archive is one with an executable in the front.

Source

pub fn entries(&self) -> &[FileMetadata<'_>]

Returns the entries found in the ZIP archive’s central directory.

No effort is made to deduplicate or otherwise validate these entries. To do that, create a FileTree.

Source

pub fn read( &self, metadata: &FileMetadata<'_>, ) -> ZipResult<Box<dyn Read + Send + 'a>>

Reads the given file from the ZIP archive.

Since each file in a ZIP archive is compressed independently, multiple files can be read in parallel.

Auto Trait Implementations§

§

impl<'a> Freeze for ZipArchive<'a>

§

impl<'a> RefUnwindSafe for ZipArchive<'a>

§

impl<'a> Send for ZipArchive<'a>

§

impl<'a> Sync for ZipArchive<'a>

§

impl<'a> Unpin for ZipArchive<'a>

§

impl<'a> UnsafeUnpin for ZipArchive<'a>

§

impl<'a> UnwindSafe for ZipArchive<'a>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.