diff --git a/src/lib.rs b/src/lib.rs index 6c39bf9..99646db 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,10 +1,12 @@ pub mod name_hashes; pub mod parsers { pub mod bhd; + pub mod bnd; pub mod dcx; } pub mod unpackers { pub mod bhd; + pub mod bnd; pub mod dcx; pub mod errors; } diff --git a/src/parsers/bnd.rs b/src/parsers/bnd.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/unpackers/bnd.rs b/src/unpackers/bnd.rs index e69de29..c620f8e 100644 --- a/src/unpackers/bnd.rs +++ b/src/unpackers/bnd.rs @@ -0,0 +1,35 @@ +use crate::parsers::bnd; +use crate::unpackers::errors::{self as unpackers_errors, UnpackError}; + +/// Extract BND file contents to disk. +/// +/// Wraps around `extract_bnd` to load the BND from disk. +pub fn extract_bnd_file(bnd_path: &str, output_path: &str) -> Result<(), UnpackError> { + let bnd = load_bnd_file(bnd_path)?; + extract_bnd(bnd, output_path)?; + Ok(()) +} + +/// Extract BND contents to disk. +pub fn extract_bnd(bnd: bnd::Bnd, output_path: &str) -> Result<(), UnpackError> { + //TODO + //let mut output_file = fs::File::create(output_path)?; + //output_file.write_all(&decomp_data)?; + Ok(()) +} + +/// Load a BND file from disk. +/// +/// Wraps around `load_bnd` to load the BND from disk. +pub fn load_bnd_file(bnd_path: &str) -> Result { + let mut bnd_file = fs::File::open(bnd_path)?; + let file_len = bnd_file.metadata()?.len() as usize; + let mut bnd_data = vec![0u8; file_len]; + bnd_file.read_exact(&mut bnd_data)?; + load_bnd(&bnd_data) +} + +/// Load a BND file from a bytes slice. +pub fn load_bnd(bnd_data: &[u8]) -> Result { + Ok(()) +}