wove/src/fs.rs
2024-10-19 17:00:04 -04:00

22 lines
511 B
Rust

use std::path::PathBuf;
use crate::{aliases::IoResult, plat_impl, Wove};
pub async fn read_to_string(wove: &Wove, path: PathBuf) -> IoResult<String> {
let mut file = plat_impl::open_file(&wove.platform, path).await?;
let mut out = Vec::new();
loop {
let buf = vec![0; 4096].into_boxed_slice();
let buf = plat_impl::read(&wove.platform, &mut file, out.len(), buf).await?;
if buf.len() == 0 {
break;
}
out.extend_from_slice(&buf);
}
String::from_utf8(out).map_err(std::io::Error::other)
}