Trait Resource

Source
pub trait Resource {
    // Required methods
    fn read(&mut self, path: &str) -> Option<ByteBuffer>;
    fn exists(&mut self, path: &str) -> bool;
}
Expand description

Represents a source of files for reading. This abstracts away some of the nitty-gritty of where files come from. These could be coming from a compressed archive like SqPack, unpacked files on disk, or even a network.

Required Methods§

Source

fn read(&mut self, path: &str) -> Option<ByteBuffer>

Reads the file located at path. This is returned as an in-memory buffer, and will usually have to be further parsed.

§Example
let mut game = SqPackResource::from_existing(Platform::Win32, "SquareEnix/Final Fantasy XIV - A Realm Reborn/game");
let data = game.read("exd/root.exl").unwrap();

let mut file = std::fs::File::create("root.exl").unwrap();
file.write(data.as_slice()).unwrap();
Source

fn exists(&mut self, path: &str) -> bool

Checks if a file exists While you could abuse read to do this, in some Resources they can optimize this since it doesn’t read data.

§Example
let mut game = SqPackResource::from_existing(Platform::Win32, "SquareEnix/Final Fantasy XIV - A Realm Reborn/game");
if game.exists("exd/cid.exl") {
    println!("Cid really does exist!");
} else {
    println!("Oh noes!");
}

Implementors§