pdbget/
input_output.rs

1use std::{fs, io, io::Write, path::PathBuf};
2
3pub fn write_file(filename: PathBuf, writer: Vec<u8>) -> Result<(), io::Error> {
4    let mut output_pdb = fs::File::create(filename)?;
5    let _ = output_pdb.write(&writer)?;
6
7    Ok(())
8}
9
10/// Check the output directory pass in argument of the program
11/// Check if the folder exist, if not create it
12/// Return an error if it's not possible, or in case of wrong permissions access
13pub fn check_output(output: &str) -> Result<PathBuf, io::Error> {
14    let path = PathBuf::from(output);
15    if path.is_dir() {
16        return Ok(path);
17    }
18    fs::create_dir(&path)?;
19    Ok(path)
20}