diff options
| author | Ryan Dahl <ry@tinyclouds.org> | 2018-08-07 00:54:18 -0400 |
|---|---|---|
| committer | Ryan Dahl <ry@tinyclouds.org> | 2018-08-09 14:27:46 -0700 |
| commit | 72544de443701a1d9907db9583db4c948517338e (patch) | |
| tree | 77ffa614d3067f6582089ecfaff58a5b3ba321ab /src/fs.rs | |
| parent | 040a0426796f0249bf0ca61ebbb2aae0b4993e94 (diff) | |
Add fs::read_file_sync_string
Diffstat (limited to 'src/fs.rs')
| -rw-r--r-- | src/fs.rs | 15 |
1 files changed, 10 insertions, 5 deletions
@@ -3,15 +3,20 @@ use std::fs::File; use std::io::Read; use std::path::Path; -#[allow(dead_code)] -pub fn read_file_sync(path: &Path) -> std::io::Result<String> { +pub fn read_file_sync(path: &Path) -> std::io::Result<Vec<u8>> { File::open(path).and_then(|mut f| { - let mut contents = String::new(); - f.read_to_string(&mut contents)?; - Ok(contents) + let mut buffer = Vec::new(); + f.read_to_end(&mut buffer)?; + Ok(buffer) }) } +pub fn read_file_sync_string(path: &Path) -> std::io::Result<String> { + let vec = read_file_sync(path)?; + String::from_utf8(vec) + .map_err(|err| std::io::Error::new(std::io::ErrorKind::InvalidData, err)) +} + pub fn mkdir(path: &Path) -> std::io::Result<()> { debug!("mkdir -p {}", path.display()); assert!(path.has_root(), "non-has_root not yet implemented"); |
