valida_vm_api_linux_x86/tmpfile_helper.rs
1use std::{fs, io::Write, path::Path};
2
3use tempfile::NamedTempFile;
4
5/// Convenience function that reads file contents as bytes. Used by the example.
6pub fn read_file_bytes(path: &Path) -> std::io::Result<Vec<u8>> {
7 fs::read(path)
8}
9
10/// Convenience function that creates a temporary file from bytes. Used by the example.
11pub fn bytes_to_temp_file(bytes: &[u8]) -> std::io::Result<NamedTempFile> {
12 let mut temp_file = NamedTempFile::new()?;
13 temp_file.write_all(bytes)?;
14 temp_file.flush()?;
15 Ok(temp_file)
16}