https://github.com/tarnadas/ninres-rs
https://github.com/tarnadas/ninres-rs
Last synced: over 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/tarnadas/ninres-rs
- Owner: Tarnadas
- Created: 2020-04-28T14:38:27.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-06T05:27:13.000Z (over 3 years ago)
- Last Synced: 2025-02-23T04:09:08.585Z (over 1 year ago)
- Language: Rust
- Size: 11.1 MB
- Stars: 12
- Watchers: 4
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Ninres-rs

[
](https://blog.rust-lang.org/2021/06/17/Rust-1.53.0.html)
[](https://discord.gg/SPZsgSe)
Read commonly used Nintendo file formats.
Please refer to the Wiki:
https://github.com/Kinnay/Nintendo-File-Formats/wiki
All file formats are behind feature flags.
Here is a list of available Nintendo file format features:
`bfres`, `sarc`
You can also enable additional features:
`tar`: write Nintendo resource to tar ball.
`zstd`: ZSTD decompression.
`png`: allows extracting textures as png.
The library is written in Rust and compiles to WebAssembly for the web or can be used as a standard Rust Crate.
A live demo running in your browser can be found here:
https://tarnadas.github.io/ninres-rs/
### Examples
Enable desired features in `Cargo.toml`.
```toml
[dependencies]
ninres = { version = "*", features = ["bfres", "sarc", "zstd"] }
```
In your `main.rs`.
```rust
use std::fs::read;
use ninres::{NinRes, NinResFile};
let buffer = read("foo.pack")?;
let ninres = buffer.as_ninres()?;
match &ninres {
NinResFile::Bfres(_bfres) => {}
NinResFile::Sarc(_sarc) => {}
}
```
## Write to tar
Convert resource into tar buffer.
This buffer can then e.g. be stored in a file.
The `mode` parameter refers to the file mode within the tar ball.
### Examples
```rust
use ninres::{sarc::Sarc, IntoTar};
use std::{fs::{read, File}, io::Write};
let sarc_file = Sarc::new(&read("./assets/M1_Model.pack")?)?;
let tar = sarc_file.into_tar(0o644)?;
let mut file = File::create("M1_Model.tar")?;
file.write_all(&tar.into_inner()[..])?;
```