#include <oead/sarc.h>

class Sarc

A simple SARC archive reader.

Public Functions

Sarc(tcb::span<const u8> data)
u16 GetNumFiles() const

Get the number of files that are stored in the archive.

u32 GetDataOffset() const

Get the offset to the beginning of file data.

util::Endianness GetEndianness() const

Get the archive endianness.

std::optional<File> GetFile(std::string_view name) const

Get a file by name.

File GetFile(u16 index) const

Get a file by index. Throws if index >= m_num_files.

auto GetFiles() const

Returns an iterator over the contained files.

size_t GuessMinAlignment() const

Guess the minimum data alignment for files that are stored in the archive.

bool operator==(const Sarc &other) const

Returns true if and only if the raw archive data is identical.

bool operator!=(const Sarc &other) const
bool AreFilesEqual(const Sarc &other) const
struct File

A file that is stored in a SARC archive.

Public Functions

bool operator==(const File &other) const
bool operator!=(const File &other) const

Public Members

std::string_view name

File name. May be empty for file entries that do not use the file name table.

tcb::span<const u8> data

File data (as a view).

class FileIterator : public InitializedIterable

File iterator.

Public Functions

FileIterator(u16 index, const Sarc &parent)
File value()
bool advance()
bool init()
class SarcWriter

Public Types

enum Mode



Used for games with an old-style resource system that requires aligning nested SARCs and manual alignment of file data in archives.


Used for games with a new-style resource system that automatically takes care of data alignment and does not require manual alignment nor nested SARC alignment.

using FileMap = absl::flat_hash_map<std::string, std::vector<u8>>


The map type is an implementation detail.

Public Functions

SarcWriter(util::Endianness endian = util::Endianness::Little, Mode mode = Mode::New)
std::pair<u32, std::vector<u8>> Write()

Write a SARC archive using the specified endianness. Default alignment requirements may be automatically added.


the required data alignment and the data.

void SetEndianness(util::Endianness endian)

Set the endianness.

void SetMinAlignment(size_t alignment)

Set the minimum data alignment.

  • alignment: Data alignment (must be a power of 2)

void AddAlignmentRequirement(std::string extension_without_dot, size_t alignment)

Add or modify a data alignment requirement for a file type. Set the alignment to 1 to revert.

  • extension_without_dot: File extension without the dot (e.g. “bgparamlist”)

  • alignment: Data alignment (must be a power of 2)

void SetMode(Mode mode)

Public Members

FileMap m_files

Files to be written.

Public Static Functions

static SarcWriter FromSarc(const Sarc &archive)

Make a SarcWriter from a SARC archive. The endianness, data alignment and file content will be copied from the SARC.

  • archive: Source archive