Skip to main content

Archive

Struct Archive 

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

A decoded, listable archive over an in-memory byte slice.

Implementations§

Source§

impl Archive

Source

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.

Source

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.

Source

pub fn format(&self) -> Format

The archive’s format.

Source

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

The archive’s member list, in archive order.

Source

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.

Source

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.

Auto Trait Implementations§

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> Same for T

Source§

type Output = T

Should always be Self
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.