diff options
Diffstat (limited to 'src/utils.rs')
| -rw-r--r-- | src/utils.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/utils.rs b/src/utils.rs new file mode 100644 index 0000000..e9d2ef1 --- /dev/null +++ b/src/utils.rs @@ -0,0 +1,22 @@ +use std::fs::File; +use std::io::{self, Read, Write}; + +pub fn save_bytes_to_file(bytes: &[u8], file_path: &str) -> io::Result<()> { + let mut file = File::create(file_path)?; + file.write_all(bytes)?; + Ok(()) +} + +pub fn read_file_as_bytes(path: &str) -> io::Result<Vec<u8>> { + // Open the file in read-only mode + let mut file = File::open(path)?; + + // Create a buffer to hold the file contents + let mut buffer = Vec::new(); + + // Read the file contents into the buffer + file.read_to_end(&mut buffer)?; + + // Return the buffer + Ok(buffer) +} |
