tools.rs: implement file_get_contents()

This commit is contained in:
Dietmar Maurer 2019-01-25 10:44:40 +01:00
parent 46b79b9ee5
commit 53157ca6cf
1 changed files with 11 additions and 0 deletions

View File

@ -77,6 +77,17 @@ pub fn file_read_firstline<P: AsRef<Path>>(path: P) -> Result<String, std::io::E
Ok(line)
}
pub fn file_get_contents<P: AsRef<Path>>(path: P) -> Result<Vec<u8>, std::io::Error> {
let mut file = std::fs::File::open(path)?;
let mut buffer = Vec::new();
file.read_to_end(&mut buffer)?;
Ok(buffer)
}
/// Atomically write a file. We first create a temporary file, which
/// is then renamed.
pub fn file_set_contents<P: AsRef<Path>>(