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<R: BufRead + Seek> Archive<R>
impl<R: BufRead + Seek> Archive<R>
Sourcepub fn new(reader: R) -> Result<Self>
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.
Sourcepub fn get_by_index(&mut self, index: usize) -> Option<File<'_, R>>
pub fn get_by_index(&mut self, index: usize) -> Option<File<'_, R>>
Gets a file by its index.
Sourcepub fn get_by_name(&mut self, name: &str) -> Option<File<'_, R>>
pub fn get_by_name(&mut self, name: &str) -> Option<File<'_, R>>
Gets a file by its name.
Sourcepub fn index_of(&self, name: &str) -> Option<usize>
pub fn index_of(&self, name: &str) -> Option<usize>
Gets the index of a file in Self::entries by its name.
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more