lqsd/src/fs.rs
Marko Korhonen 5f81577b83
Initial commit
Signed-off-by: Marko Korhonen <marko.korhonen@reekynet.com>
2020-01-19 21:33:52 +02:00

22 lines
561 B
Rust

use std::fs::{remove_file, File};
use std::io::prelude::*;
use std::path::PathBuf;
pub fn write(path: &PathBuf, contents: String) -> std::io::Result<()> {
let mut file = File::create(path)?;
file.write_all(contents.as_bytes())?;
file.sync_data()?;
Ok(())
}
pub fn read(path: &PathBuf) -> std::io::Result<String> {
let mut file = File::open(path)?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;
Ok(contents)
}
pub fn remove(path: &PathBuf) -> std::io::Result<()> {
remove_file(path)?;
Ok(())
}