Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

BSA archive format

Implemented in CreationEngineFormats/ArchiveFile/. Reference: UESP Archive File Format.

BsaListingReader.ReadAsync reads the blocks in the order the format requires (each offset depends on the previous block) and returns a flat list of entries. BsaFileExtractor reads one entry’s data on demand.

VersionGameCompressionFolder record
104Skyrimzlib16 bytes
105Skyrim Special EditionLZ4 frame24 bytes

The 36-byte header (Reader/HeaderReader.cs) follows the spec as written. BsaArchiveFlags lists every archive flag of the spec. The ones the readers act on:

FlagValueEffect
IncludeDirectoryNames0x1Each file record block starts with the folder name
IncludeFileNames0x2The file name block is present
CompressedArchive0x4Files are compressed by default
EmbedFileNames0x100Each file block starts with the file’s path

Blocks

BlockReaderLayout
Folder recordsFolderRecordsReaderv104: hash (8), file count (4), offset (4). v105 adds 4 padding bytes after the count and after the offset
File record blocksFileRecordBlocksReaderPer folder: name as a bzstring (if 0x1), then one record per file: hash (8), size (4), offset (4)
File name blockFileNameBlockReaderOne null-terminated name per file, in file record order (if 0x2)

A folder record’s offset counts the file name block even though that block comes after the file record blocks: the reader subtracts the total file name length. The file name block is read in one call of that length, then split on the \0s; \0 padding after the last name is skipped, see Assumptions. Without a file name block, an entry is named after its hash.

In a file record’s size, bit 30 (0x40000000) inverts the archive’s default compression for that file. BsaFileRecord.ActualSize masks it out, IsCompressed(flags) applies it.

File blocks

FieldPresent when
Path as a bstringEmbedFileNames is set
uint32 original sizeThe file is compressed
DataAlways

Version 105 stores each compressed file as a full LZ4 frame (magic 04 22 4D 18), not a raw LZ4 block. The block decoder LZ4Codec.Decode doesn’t throw on a frame: it returns data of the right length with the first bytes corrupted. BsaFileExtractor uses the frame decoder LZ4Stream.Decode.

String tables

.strings, .dlstrings and .ilstrings files live under Strings\, named <plugin>_<language>.<extension>. Vanilla ships them in Skyrim - Interface.bsa. Reference: UESP String Table File Format. SkyrimStringTable.Decode reads them.

PartLayout
Headeruint32 count, uint32 data size
DirectoryPer entry: uint32 string id, uint32 offset into the data. Not required to be sorted
Data (.strings)Null-terminated strings
Data (.dlstrings, .ilstrings)uint32 length, null included, then the string

Encodings and the fallback rules are in Localization.

Several archives

Vanilla content is split over several archives, and each plugin can add its own. The exporter merges them into one path index, the archive file system (Game/Bsa/ArchiveFileSystem.cs), see Load order: when a path is in several archives, the last one wins, see Spec deviations. A loose file in Data overrides every archive, see Loose files. Each archive keeps one stream; extraction seeks and reads under a per-archive lock, so entries can be extracted from several threads.