Module rstb::calc[][src]

Expand description

Provides functions for calculating or estimating resource size values.

Sample usage:

use std::fs::read;
use rstb::calc::*;
// Calculate RSTB value for file on disk
assert_eq!(
    calculate_size(
        "A-1_Dynamic.smubin",
        Endian::Big,
        false
    ).unwrap()
        .unwrap(),
    48800
);

// Or we can calculate from a buffer if we provide the file extension
let buf: Vec<u8> = read("A-1_Dynamic.smubin").unwrap();
assert_eq!(
    calculate_size_with_ext(
        &buf,
        ".smubin",
        Endian::Big,
        false
    ).unwrap(),
    48800
);

Functions

calculate_size

Attempts to calculate the resource size for an existant file from its path, optionally applying a statistical estimate for some complex resource types. Note that the endian parameter should be specified as Big for Wii U and Little for Switch even if the file type itself always uses the same endianness (e.g. AAMP files are always little endian).

calculate_size_with_ext

Attempts to calculate the resource size for a file given its contents and file extension, optionally applying a statistical estimate for some complex resource types. Note that the endian parameter should be specified as Big for Wii U and Little for Switch even if the file type itself always uses the same endianness (e.g. AAMP files are always little endian).

guess_bfres_value_from_file

Estimates the resource size for BFRES files on the file system. Returns a Result with the estimated resource size or an IO/file system error.

guess_bfres_value_from_size

Estimates the resource size for BFRES files from the uncompressed file size. Unlike other RSTB calculators, this will always return a real value.

guess_size

Estimates the resource size for complex resource types, excluding BFRES. Returns None if no estimate is available.