use crate::*;
pub fn write_to_file(file_path: &str, content: &[u8]) -> Result<(), Error> {
if let Some(parent_dir) = std::path::Path::new(file_path).parent() {
std::fs::create_dir_all(parent_dir)?;
}
std::fs::OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.open(file_path)
.and_then(|mut file| std::io::Write::write_all(&mut file, content))
}
pub fn append_to_file(file_path: &str, content: &[u8]) -> Result<(), Error> {
if let Some(parent_dir) = std::path::Path::new(file_path).parent() {
std::fs::create_dir_all(parent_dir)?;
}
std::fs::OpenOptions::new()
.create(true)
.append(true)
.open(file_path)
.and_then(|mut file| std::io::Write::write_all(&mut file, content))
}