18 lines
539 B
Rust
18 lines
539 B
Rust
use mktemp::Temp;
|
|
use rand::Rng;
|
|
|
|
/// Create a temporary file and feed it with some specified content
|
|
pub fn create_temp_file_with_content(content: &[u8]) -> Temp {
|
|
let temp = Temp::new_file().unwrap();
|
|
std::fs::write(&temp, content).unwrap();
|
|
temp
|
|
}
|
|
|
|
/// Generate a temporary file with some random content
|
|
pub fn create_temp_file_with_random_content() -> Temp {
|
|
let random_bytes = rand::thread_rng().gen::<[u8; 10]>();
|
|
let temp = Temp::new_file().unwrap();
|
|
std::fs::write(&temp, random_bytes).unwrap();
|
|
temp
|
|
}
|