1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use std::fs::File;
use std::io::Read;
use std::io::Write;

pub fn file_to_vec(file_path: &str, v: &mut Vec<u8>) {
    let mut file= match File::open(file_path) {
        Result::Ok(val) => val,
        Result::Err(err) => panic!("{:?}", err)
    };

    match file.read_to_end(v) {
        Ok(val) => val,
        Err(err) => panic!("{:?}", err)
    };
}


pub fn vec_to_file(file_path: &str, v: &mut Vec<u8>) {
    let mut file_out= match File::create(file_path) {
        Result::Ok(val) => val,
        Result::Err(err) => panic!("{:?}", err)
    };

    match file_out.write_all(v) {
        Result::Ok(val) => val,
        Result::Err(err) => panic!("{:?}", err)
    };
}