Expand description
BIF archive support. BIF binary reader and writer.
BIF (BIFF) files are archive containers referenced by KEY indexes.
Each entry stores only (resource_id, type_id, payload); names/resrefs are
resolved through KEY metadata.
§Format Layout
+------------------------------+ 0x0000
| Header (20 bytes) |
+------------------------------+ variable_table_offset
| Variable resource table |
| 16 bytes * resource_count |
+------------------------------+ (optional)
| Fixed resource table |
| 20 bytes * fixed_count |
+------------------------------+ offsets from table
| Resource payload blob |
| (aligned to 4-byte boundary) |
+------------------------------+§Variable Resource Entry (16 bytes)
0x00..0x04 resource_id (u32)
0x04..0x08 data_offset (u32)
0x08..0x0C data_size (u32)
0x0C..0x10 type_id (u32; validated to u16 range)§Fixed Resource Entry (20 bytes)
0x00..0x04 resource_id (u32)
0x04..0x08 data_offset (u32)
0x08..0x0C part_count (u32)
0x0C..0x10 data_size (u32)
0x10..0x14 type_id (u32; validated to u16 range)§Compressed Variant (.bzf)
The mobile ports ship the same archives with each payload individually
LZMA-compressed. The container is otherwise identical, which is the
awkward part: the signature is still BIFF, the header and tables are
byte-for-byte the same shape, and the KEY still names the file .bif.
Only the on-disk extension distinguishes them.
+------------------------------+ 0x0000
| Header (20 bytes) | identical, signature still `BIFF`
+------------------------------+ variable_table_offset
| Variable resource table | data_size = UNCOMPRESSED length
+------------------------------+ offsets from table
| Payload: LZMA-alone stream | 5-byte header, no length field
| 0x00 properties byte | packs (pb * 5 + lp) * 9 + lc
| 0x01..05 dictionary size | u32
| 0x05.. compressed data | ends with an end-of-stream marker
+------------------------------+An entry’s packed extent is not stored anywhere. It runs from the entry’s offset to wherever the next entry begins, with the last running to the end of the file. The uncompressed length in the table is what the decoder is told to produce.
Notes:
- Vanilla KotOR BIFs typically use only variable-resource entries
(
fixed_count == 0), but files with fixed-table entries are accepted. - Compressed archives are gated behind the crate feature
bzfand read throughBifIndex, which takes the container kind from the caller rather than guessing it from content.
Structs§
- Bif
- In-memory BIF archive.
- BifIndex
- A lazily-read BIF archive.
- BifIndex
Entry - One indexed resource: its identity and where its bytes live.
- BifRead
Options - BIF reader option set.
- BifResource
- One resource entry stored in a BIF archive.
Enums§
- BifBinary
Error - Errors produced while parsing or serializing BIF binary data.
- BifContainer
- BIF container kind.
- BifRead
Mode - BIF reader input policy.
- BifResource
Storage - Storage table kind for a
BifResource.
Functions§
- read_
bif - Reads a BIF archive from a reader.
- read_
bif_ from_ bytes - Reads a BIF archive from bytes.
- read_
bif_ from_ bytes_ with_ options - Reads a BIF archive from bytes with explicit options.
- read_
bif_ with_ options - Reads a BIF archive from a reader with explicit options.
- write_
bif - Writes a BIF archive to a writer.
- write_
bif_ to_ vec - Serializes a BIF archive to bytes.