aboutsummaryrefslogtreecommitdiff
path: root/src/utils.rs
blob: e9d2ef1c10d5b8d26d824ad1992540956353542c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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)
}