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>
impl BifIndex<File>
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Self, BifBinaryError>
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.
Sourcepub fn open_with_options(
path: impl AsRef<Path>,
options: BifReadOptions,
) -> Result<Self, BifBinaryError>
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>
impl<R: Read + Seek> BifIndex<R>
Sourcepub fn new(section: SectionReader<R>) -> Result<Self, BifBinaryError>
pub fn new(section: SectionReader<R>) -> Result<Self, BifBinaryError>
Indexes an uncompressed archive occupying section.
Sourcepub fn new_with_container(
section: SectionReader<R>,
container: BifContainer,
) -> Result<Self, BifBinaryError>
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.
Sourcepub fn new_with_options(
section: SectionReader<R>,
container: BifContainer,
options: BifReadOptions,
) -> Result<Self, BifBinaryError>
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.
Sourcepub fn read_entry(&self, position: usize) -> Result<Vec<u8>, BifBinaryError>
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.
Sourcepub fn container(&self) -> BifContainer
pub fn container(&self) -> BifContainer
Returns the container kind this archive was opened as.
Sourcepub fn resolve_by_id(
&self,
resource_id: ResourceId,
) -> Result<Option<Vec<u8>>, BifBinaryError>
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.
Sourcepub fn entry_section(&self, position: usize) -> Option<SectionReader<R>>
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.
Sourcepub fn iter_resources(
&self,
) -> impl Iterator<Item = Result<(&BifIndexEntry, Vec<u8>), BifBinaryError>> + '_
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>
impl<R> BifIndex<R>
Sourcepub fn entries(&self) -> &[BifIndexEntry]
pub fn entries(&self) -> &[BifIndexEntry]
Returns the indexed entries in table order.
Sourcepub fn entry(&self, position: usize) -> Option<&BifIndexEntry>
pub fn entry(&self, position: usize) -> Option<&BifIndexEntry>
Returns the entry at position without reading its bytes.
Sourcepub fn contains_id(&self, resource_id: ResourceId) -> bool
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.
Sourcepub fn defects(
&self,
) -> impl Iterator<Item = (usize, &BifIndexEntry, &EntryDefect)> + '_
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.
Sourcepub fn has_defects(&self) -> bool
pub fn has_defects(&self) -> bool
Returns whether any entry in the archive is unreadable.