pub struct Archive { /* private fields */ }Expand description
A decoded, listable archive over an in-memory byte slice.
Implementations§
Source§impl Archive
impl Archive
Sourcepub fn open(data: &[u8], name: Option<&str>) -> Result<Option<Archive>>
pub fn open(data: &[u8], name: Option<&str>) -> Result<Option<Archive>>
Open data as one of the four archive formats, returning Ok(None) when
it is not an archive (a bare wrapper or unrecognized input). name is an
optional file-name hint used only to distinguish a compressed tar
(.tgz/.tbz2) from a bare gzip/bzip2 stream.
§Errors
ArchiveError::Open if the archive directory cannot be parsed (a
malformed outer compression layer surfaces here while streaming the tar
listing). The tar family is listed by streaming, so no whole-archive
inflate happens at open; the [crate::peel::MAX_INFLATED] cap is enforced
per member in read.
Sourcepub fn member_access(&mut self, index: usize) -> Result<Access>
pub fn member_access(&mut self, index: usize) -> Result<Access>
The most-seekable Access for member index, chosen from the member
table without decompressing (ADR 0008, rule 4). A Stored/uncompressed
zip member is InPlace (zero-copy sub-range); Deflate/Deflate64 is
Zran; every other codec — and tar/7z members, which expose no
in-archive offset or use a non-seekable codec — is SpillToTemp.
§Errors
ArchiveError::IndexOutOfRange for a bad index, or ArchiveError::Read
if a zip member’s local header cannot be read.
Sourcepub fn entries(&self) -> &[ArchiveEntry]
pub fn entries(&self) -> &[ArchiveEntry]
The archive’s member list, in archive order.
Sourcepub fn read(&mut self, index: usize) -> Result<Vec<u8>>
pub fn read(&mut self, index: usize) -> Result<Vec<u8>>
Extract the bytes of the member at index, capped at
[crate::peel::MAX_INFLATED].
§Errors
ArchiveError::IndexOutOfRange for a bad index, ArchiveError::Read
on a backend/codec failure, or ArchiveError::TooLarge past the cap.
Sourcepub fn stream_member(
&mut self,
index: usize,
out: &mut dyn Write,
cap: u64,
) -> Result<u64>
pub fn stream_member( &mut self, index: usize, out: &mut dyn Write, cap: u64, ) -> Result<u64>
Stream the bytes of member index into out, capped at cap. The member
is copied through a bounded buffer — never fully materialized in a Vec —
so a multi-GB inner image spills to the caller’s writer (a temp file)
without holding it in RAM. Fails loud with ArchiveError::TooLarge past
cap. Returns the number of bytes written.
The one exception is a 7z member: sevenz-rust2 exposes no streaming
extract, so its bytes pass through a transient Vec before the write.
§Errors
ArchiveError::IndexOutOfRange for a bad index, ArchiveError::Read
on a backend/codec failure, or ArchiveError::TooLarge past cap.