diff options
author | cc <cc@localhost> | 2025-08-20 18:59:47 -0700 |
---|---|---|
committer | cc <cc@localhost> | 2025-08-20 18:59:59 -0700 |
commit | b0ff49fdd4ae82af5cf89180078ea7314072c29f (patch) | |
tree | 0287a8cf3f04f7a040578a4e14ec446a47b6c4a7 | |
parent | 27d77b602e2d43a8bab413d69b86c38e53435a8e (diff) |
Add binary file output function
-rw-r--r-- | src/binfile.rs | 14 | ||||
-rw-r--r-- | src/lib.rs | 11 |
2 files changed, 18 insertions, 7 deletions
diff --git a/src/binfile.rs b/src/binfile.rs new file mode 100644 index 0000000..9b50a70 --- /dev/null +++ b/src/binfile.rs @@ -0,0 +1,14 @@ +pub fn dump_u32_vec(file_name: &str, data: Vec<u32>) -> Result<(), String> { + use std::fs::File; + use std::io::Write; + if let Ok(mut file) = File::create(file_name) { + for value in data { + if let Err(error) = file.write_all(&value.to_le_bytes()) { + return Err(error.to_string()); + } + } + } else { + return Err(String::from("Error creating file")); + } + Ok(()) +} @@ -1,4 +1,7 @@ pub mod tiff; +mod binfile; + +pub use binfile::dump_u32_vec; pub const TEST_IMAGE_PATH: &str = "../test.tif"; pub const TEST_OUTPUT_PATH: &str = "../test.bin"; @@ -77,15 +80,9 @@ mod tests { #[test] fn tiff_data_dump_test() { - use std::fs::File; - use std::io::Write; tiff::ignore_warnings(); if let Some(standard_format) = tiff::as_standard_format(TEST_IMAGE_PATH) { - if let Ok(mut file) = File::create(TEST_OUTPUT_PATH) { - for value in standard_format { - let _ = file.write_all(&value.to_le_bytes()); - } - } + dump_u32_vec(TEST_OUTPUT_PATH, standard_format).expect("File output error"); } else { assert!(false); } |