~exprez135/castor

ref: 0.8.4 castor/src/client.rs -rw-r--r-- 470 bytes
193de0c2Julien Blanchard [gopher] Fix parsing of h type 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use std::io::Write;
use tempfile::NamedTempFile;

pub trait Client {
    fn get_data(&self) -> Result<(Option<Vec<u8>>, Vec<u8>), String>;
}

pub fn download(content: Vec<u8>) {
    let path = write_tmp_file(content);
    open::that(path).unwrap();
}

fn write_tmp_file(content: Vec<u8>) -> std::path::PathBuf {
    let mut tmp_file = NamedTempFile::new().unwrap();
    tmp_file.write_all(&content).unwrap();
    let (_file, path) = tmp_file.keep().unwrap();
    path
}