pub struct KeyFile { /* private fields */ }Expand description
Read-only KEY/BIF lookup wrapper.
Implementations§
Source§impl KeyFile
impl KeyFile
Sourcepub fn read_from_file(key_path: impl AsRef<Path>) -> Result<Self, KeyFileError>
pub fn read_from_file(key_path: impl AsRef<Path>) -> Result<Self, KeyFileError>
Reads a KEY file and binds BIF lookups to the KEY parent directory.
Sourcepub fn read_from_file_with_base(
key_path: impl AsRef<Path>,
bif_base_path: impl AsRef<Path>,
) -> Result<Self, KeyFileError>
pub fn read_from_file_with_base( key_path: impl AsRef<Path>, bif_base_path: impl AsRef<Path>, ) -> Result<Self, KeyFileError>
Reads a KEY file and binds BIF lookups to an explicit base directory.
Sourcepub fn bif_base_path(&self) -> &Path
pub fn bif_base_path(&self) -> &Path
Returns the BIF base path used for KEY filename resolution.
Sourcepub fn resource_entry(
&self,
resref: &ResRef,
resource_type: ResourceTypeCode,
) -> Option<&KeyResourceEntry>
pub fn resource_entry( &self, resref: &ResRef, resource_type: ResourceTypeCode, ) -> Option<&KeyResourceEntry>
Returns the first matching KEY entry for (resref, type).
Sourcepub fn bif_path_by_index(&self, bif_index: u32) -> Option<PathBuf>
pub fn bif_path_by_index(&self, bif_index: u32) -> Option<PathBuf>
Resolves one BIF path by KEY BIF index.
Resolution order:
- direct
<base>/<key-relative-path> <base>/data/<key-relative-path>- case-insensitive indexed relative path match
- case-insensitive indexed basename match
Sourcepub fn read_bif_by_index(&self, bif_index: u32) -> Result<Bif, KeyFileError>
pub fn read_bif_by_index(&self, bif_index: u32) -> Result<Bif, KeyFileError>
Reads one BIF archive by KEY BIF index.
Sourcepub fn resource(
&self,
resref: &ResRef,
resource_type: ResourceTypeCode,
) -> Result<Option<Vec<u8>>, KeyFileError>
pub fn resource( &self, resref: &ResRef, resource_type: ResourceTypeCode, ) -> Result<Option<Vec<u8>>, KeyFileError>
Resolves one payload by (resref, type).
Returns Ok(None) when the KEY has no matching entry.
This uses seek-based I/O to read only the requested resource from the BIF file, avoiding loading the entire (often hundreds of MB) BIF into memory.
Sourcepub fn read_resource_by_seek(
&self,
bif_index: u32,
resource_id: ResourceId,
) -> Result<Vec<u8>, KeyFileError>
pub fn read_resource_by_seek( &self, bif_index: u32, resource_id: ResourceId, ) -> Result<Vec<u8>, KeyFileError>
Reads a single resource from a BIF file using seek-based I/O.
Instead of loading the entire BIF into memory, this reads only the BIF variable table header (a few KB) and then seeks directly to the requested resource’s data. This is dramatically more memory-efficient for large BIF files.