Skip to main content

BifIndex

Struct BifIndex 

Source
pub struct BifIndex<R = File> { /* private fields */ }
Expand description

A lazily-read BIF archive.

Holds both resource tables; payload bytes are read from the backing source on each request.

Compressed archives are supported behind the bzf feature: each entry’s packed extent is derived from offset ordering and decompressed on read, so the owned-bytes contract is identical either way and callers need not care which kind they mounted.

Implementations§

Source§

impl BifIndex<File>

Source

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

Opens an archive from disk and indexes it.

Compression is inferred from the path: a .bzf extension (case-insensitive) means LZMA-compressed payloads, anything else means plain. That is the only signal shipping data carries — the file signature is BIFF either way — so it is read here rather than guessed from content.

Errors when the file cannot be opened, its tables do not parse, or it is compressed and the bzf feature is off.

Source

pub fn open_with_options( path: impl AsRef<Path>, options: BifReadOptions, ) -> Result<Self, BifBinaryError>

Opens an archive from disk with explicit read options.

Compression is inferred from the path as in Self::open.

Source§

impl<R: Read + Seek> BifIndex<R>

Source

pub fn new(section: SectionReader<R>) -> Result<Self, BifBinaryError>

Indexes an uncompressed archive occupying section.

Source

pub fn new_with_container( section: SectionReader<R>, container: BifContainer, ) -> Result<Self, BifBinaryError>

Indexes an archive occupying section, stating its container kind.

Windowed constructors take the kind explicitly because a window has no filename to read it from.

Source

pub fn new_with_options( section: SectionReader<R>, container: BifContainer, options: BifReadOptions, ) -> Result<Self, BifBinaryError>

Indexes the archive occupying section with explicit read options.

Reads both resource tables immediately. A table that will not parse fails here, because nothing about the archive is knowable without it. An entry whose declared byte range escapes the archive does not: it is marked with a defect and the rest stays readable.

Source

pub fn read_entry(&self, position: usize) -> Result<Vec<u8>, BifBinaryError>

Reads the bytes of the entry at position in table order.

This is the lookup a KEY table drives: its rows carry the resource’s position within the BIF.

Source

pub fn container(&self) -> BifContainer

Returns the container kind this archive was opened as.

Source

pub fn resolve_by_id( &self, resource_id: ResourceId, ) -> Result<Option<Vec<u8>>, BifBinaryError>

Reads the bytes of the resource carrying resource_id.

Returns Ok(None) when no entry carries that id, and Err only when a matching entry exists but its bytes cannot be read.

Source

pub fn entry_section(&self, position: usize) -> Option<SectionReader<R>>

Returns a window over the entry’s bytes without reading them.

Returns None when position is out of range or the entry carries a defect.

Source

pub fn iter_resources( &self, ) -> impl Iterator<Item = Result<(&BifIndexEntry, Vec<u8>), BifBinaryError>> + '_

Iterates every resource, pairing its entry with freshly-read bytes.

Each item is read on demand, so a caller that stops early pays only for what it consumed.

Source§

impl<R> BifIndex<R>

Source

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

Returns the indexed entries in table order.

Source

pub fn entry(&self, position: usize) -> Option<&BifIndexEntry>

Returns the entry at position without reading its bytes.

Source

pub fn len(&self) -> usize

Returns the number of indexed resources.

Source

pub fn is_empty(&self) -> bool

Returns whether the archive holds no resources.

Source

pub fn contains_id(&self, resource_id: ResourceId) -> bool

Returns whether the archive holds a resource with resource_id.

True even when the entry is defective: the archive claims the resource exists, it just cannot be read.

Source

pub fn defects( &self, ) -> impl Iterator<Item = (usize, &BifIndexEntry, &EntryDefect)> + '_

Iterates the entries that cannot be read, with their table positions.

Whatever mounts this archive is expected to surface these rather than let a partially-readable archive pass as intact.

Source

pub fn has_defects(&self) -> bool

Returns whether any entry in the archive is unreadable.

Trait Implementations§

Source§

impl<R: Debug> Debug for BifIndex<R>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<R> Freeze for BifIndex<R>

§

impl<R> RefUnwindSafe for BifIndex<R>

§

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

§

impl<R> Sync for BifIndex<R>
where R: Send,

§

impl<R> Unpin for BifIndex<R>

§

impl<R> UnsafeUnpin for BifIndex<R>

§

impl<R> UnwindSafe for BifIndex<R>

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

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
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> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> StrictAs for T

Source§

fn strict_as<Dst>(self) -> Dst
where T: StrictCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> StrictCastFrom<Src> for Dst
where Src: StrictCast<Dst>,

Source§

fn strict_cast_from(src: Src) -> Dst

Casts the value.
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.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.