Archive

Struct Archive 

Source
pub struct Archive<R> { /* private fields */ }
Expand description

An open ZIP archive.

This type owns the reader. If you need something more flexible, use RawArchive instead.

§Example

Print the name and content of each file in the archive:

let mut archive = eazip::Archive::open("example.zip")?;

for i in 0..archive.entries().len() {
    let mut entry = archive.get_by_index(i).unwrap();
    let name = entry.metadata().name();
    let content = std::io::read_to_string(entry.read()?)?;

    println!("{name}: {content}");
}

Implementations§

Source§

impl Archive<BufReader<File>>

Source

pub fn open(path: impl AsRef<Path>) -> Result<Self>

Opens the given file as a ZIP archive.

Source§

impl<R: BufRead + Seek> Archive<R>

Source

pub fn new(reader: R) -> Result<Self>

Opens a ZIP archive from a reader.

This also perform many validation checks on the archive to make sure that is it well-formed and does not have dangerous or duplicated paths. The validity of file contents is checked lazily when reading them.

The exact rules around validation are not part of semver guaranties and may change at every release.

The targets of symlinks are not checked yet here, though they are through extract and extract_parallel.

Source

pub fn entries(&self) -> &[Metadata]

Gets the list of entries in the archive.

Source

pub fn get_by_index(&mut self, index: usize) -> Option<File<'_, R>>

Gets a file by its index.

Source

pub fn get_by_name(&mut self, name: &str) -> Option<File<'_, R>>

Gets a file by its name.

Source

pub fn index_of(&self, name: &str) -> Option<usize>

Gets the index of a file in Self::entries by its name.

Source

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

Gets the comment of the archive.

Source

pub fn extract(&mut self, at: impl AsRef<Path>) -> Result<()>

Extracts the archive to the given directory.

The directory will be created if needed, but not its parent.

Source

pub fn get_ref(&self) -> &R

Gets a shared reference to the underlying reader.

Source

pub fn get_mut(&mut self) -> &mut R

Gets a mutable reference to the underlying reader.

Auto Trait Implementations§

§

impl<R> Freeze for Archive<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for Archive<R>
where R: RefUnwindSafe,

§

impl<R> Send for Archive<R>
where R: Send,

§

impl<R> Sync for Archive<R>
where R: Sync,

§

impl<R> Unpin for Archive<R>
where R: Unpin,

§

impl<R> UnwindSafe for Archive<R>
where R: UnwindSafe,

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.