Module roead::sarc

source ·
Expand description

Port of the oead::sarc module.

Unlike the other modules in this crate, this does not provide bindings to oead but is a port of its SARC implementation. Why? Because SARC is a simple format, so much so that it is easier to reimplement than to do FFI.

Sample usage, just reading a SARC:

let data = std::fs::read("test/sarc/Dungeon119.pack")?;
let sarc: Sarc = Sarc::new(&data)?; // In this case we borrow data, but we can also own
assert_eq!(sarc.len(), 10); // Get the number of files
assert_eq!(sarc.guess_min_alignment(), 4);
for file in sarc.files() {
    println!("File name: {}", file.name().unwrap());
    do_stuff_with_data(file.data());
}

And writing a SARC:

let mut sarc_writer = SarcWriter::new(Endian::Big); // Create an empty SARC
sarc_writer.set_min_alignment(4); // Set the alignment, if needed
sarc_writer
    .files
    .insert("A/Dummy/File.txt".into(), b"This is a test".to_vec()); // Add a couple files
sarc_writer
    .files
    .insert("A/Dummy/File2.txt".into(), b"This is another test".to_vec());
sarc_writer.remove_file("A/Dummy/File.txt"); // Never mind!
let data = sarc_writer.to_binary(); // Write to an in-memory buffer
// We can also take construct a SARC writer from an existing SARC
let sarc = Sarc::new(data.as_slice())?;
let another_sarc_writer = SarcWriter::from_sarc(&sarc);

Structs§

  • Provides readonly access to a file that is stored in a SARC archive.
  • A simple SARC archive reader
  • A simple SARC archive writer

Functions§