This repository has been archived on 2025-03-28. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
tcp-over-http/src/test/test_files_utils.rs

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
}