Factor out the code for reading a file into a utility function.

This commit is contained in:
Dan Gohman
2017-10-03 09:09:48 -07:00
parent f064418652
commit ba14499fe9
2 changed files with 13 additions and 12 deletions

View File

@@ -20,6 +20,14 @@ pub fn read_to_string<P: AsRef<Path>>(path: P) -> io::Result<String> {
Ok(buffer)
}
/// Read an entire file into a vector of bytes.
pub fn read_to_end<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> {
let mut file = File::open(path)?;
let mut buffer = Vec::new();
file.read_to_end(&mut buffer)?;
Ok(buffer)
}
/// Look for a directive in a comment string.
/// The directive is of the form "foo:" and should follow the leading `;` in the comment:
///