pub struct ZipArchive<'a> { /* private fields */ }Expand description
A parsed ZIP archive. Construction finds the end-of-central-directory
record and parses the whole central directory; payload bytes are only
touched by ZipArchive::extract.
Implementations§
Source§impl<'a> ZipArchive<'a>
impl<'a> ZipArchive<'a>
Sourcepub fn new(data: &'a [u8]) -> Result<Self>
pub fn new(data: &'a [u8]) -> Result<Self>
Parses data as a ZIP archive: finds the EOCD (searching backwards
over a comment of up to 64 KiB), checks the single-disk and
non-ZIP64 invariants, and parses every central directory entry.
The directory must sit exactly where the EOCD says and end exactly where the EOCD starts; archives that smuggle extra bytes between directory entries are malformed by definition (APPNOTE §4.3.12).
Sourcepub fn by_name(&self, name: &str) -> Option<&ZipEntry<'a>>
pub fn by_name(&self, name: &str) -> Option<&ZipEntry<'a>>
The entry with this exact member name (byte-exact match — the
archive’s own convention), or None.
Sourcepub fn extract(&self, entry: &ZipEntry<'a>) -> Result<Vec<u8>>
pub fn extract(&self, entry: &ZipEntry<'a>) -> Result<Vec<u8>>
Extracts entry and verifies it: sizes first, CRC-32 last. The
entry must come from this archive’s entries or
by_name — it carries offsets into self.data.
Extraction is refused with Error::Unsupported for encrypted
entries and compression methods other than stored (0) and DEFLATE
(8), and Error::BadValue when the local header disagrees with
the central directory, a data descriptor’s numbers do not match
the directory’s, the decompressed length is wrong, or the CRC-32
does not match.
Sourcepub fn extract_by_name(&self, name: &str) -> Result<Vec<u8>>
pub fn extract_by_name(&self, name: &str) -> Result<Vec<u8>>
Extracts the named entry: Error::BadValue ("no such zip entry") when the name is absent, otherwise exactly
extract.