pub struct RimIndex<R = File> { /* private fields */ }Expand description
A lazily-read RIM archive.
Holds the archive’s key table and reserved header fields; resource bytes are read from the backing source on each request.
Implementations§
Source§impl RimIndex<File>
impl RimIndex<File>
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Self, RimBinaryError>
pub fn open(path: impl AsRef<Path>) -> Result<Self, RimBinaryError>
Opens an archive from disk and indexes it.
Errors when the file cannot be opened or its key table does not parse.
Sourcepub fn open_with_options(
path: impl AsRef<Path>,
options: RimReadOptions,
) -> Result<Self, RimBinaryError>
pub fn open_with_options( path: impl AsRef<Path>, options: RimReadOptions, ) -> Result<Self, RimBinaryError>
Opens an archive from disk with explicit read options.
Source§impl<R: Read + Seek> RimIndex<R>
impl<R: Read + Seek> RimIndex<R>
Sourcepub fn new(section: SectionReader<R>) -> Result<Self, RimBinaryError>
pub fn new(section: SectionReader<R>) -> Result<Self, RimBinaryError>
Indexes the archive occupying section.
Sourcepub fn new_with_options(
section: SectionReader<R>,
options: RimReadOptions,
) -> Result<Self, RimBinaryError>
pub fn new_with_options( section: SectionReader<R>, options: RimReadOptions, ) -> Result<Self, RimBinaryError>
Indexes the archive occupying section with explicit read options.
Reads the header and key table 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 resolve(
&self,
resref: &ResRef,
resource_type: ResourceTypeCode,
) -> Result<Option<Vec<u8>>, RimBinaryError>
pub fn resolve( &self, resref: &ResRef, resource_type: ResourceTypeCode, ) -> Result<Option<Vec<u8>>, RimBinaryError>
Reads the bytes of the resource named resref with resource_type.
Returns Ok(None) when the archive holds no such resource, and Err
only when a matching entry exists but its bytes cannot be read.
Sourcepub fn read_entry(&self, index: usize) -> Result<Vec<u8>, RimBinaryError>
pub fn read_entry(&self, index: usize) -> Result<Vec<u8>, RimBinaryError>
Reads the bytes of the entry at index in table order.
Errors when index is out of range, the entry carries a defect, or
the read itself fails.
Sourcepub fn entry_section(&self, index: usize) -> Option<SectionReader<R>>
pub fn entry_section(&self, index: usize) -> Option<SectionReader<R>>
Returns a window over the entry’s bytes without reading them.
Returns None when index is out of range or the entry carries a
defect.
Sourcepub fn resource_section(
&self,
resref: &ResRef,
resource_type: ResourceTypeCode,
) -> Option<SectionReader<R>>
pub fn resource_section( &self, resref: &ResRef, resource_type: ResourceTypeCode, ) -> Option<SectionReader<R>>
Returns a window over the named resource’s bytes without reading them.
Sourcepub fn iter_resources(
&self,
) -> impl Iterator<Item = Result<(&RimIndexEntry, Vec<u8>), RimBinaryError>> + '_
pub fn iter_resources( &self, ) -> impl Iterator<Item = Result<(&RimIndexEntry, Vec<u8>), RimBinaryError>> + '_
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> RimIndex<R>
impl<R> RimIndex<R>
Sourcepub fn entries(&self) -> &[RimIndexEntry]
pub fn entries(&self) -> &[RimIndexEntry]
Returns the indexed entries in table order.
Sourcepub fn contains(&self, resref: &ResRef, resource_type: ResourceTypeCode) -> bool
pub fn contains(&self, resref: &ResRef, resource_type: ResourceTypeCode) -> bool
Returns whether the archive holds the named resource.
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, &RimIndexEntry, &EntryDefect)> + '_
pub fn defects( &self, ) -> impl Iterator<Item = (usize, &RimIndexEntry, &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.
Sourcepub fn reserved_0x08(&self) -> u32
pub fn reserved_0x08(&self) -> u32
Returns the reserved header word at 0x08.
Preserved so a writer can reproduce the archive’s header verbatim.
Sourcepub fn reserved_0x14(&self) -> u32
pub fn reserved_0x14(&self) -> u32
Returns the reserved header word at 0x14.
Sourcepub fn reserved_0x18(&self) -> &[u8; 96]
pub fn reserved_0x18(&self) -> &[u8; 96]
Returns the reserved header block at 0x18.