Download crates/forge_fs/src/read.rs from SaylorTwift/forgecode: direct link, hf CLI and curl.
- Browser
- Download file 753 Bytes
-
https://huggingface.co/SaylorTwift/forgecode/resolve/main/crates/forge_fs/src/read.rs
- Command line
-
hf download hf://SaylorTwift/forgecode/crates/forge_fs/src/read.rs
-
curl -L -o read.rs https://huggingface.co/SaylorTwift/forgecode/resolve/main/crates/forge_fs/src/read.rs
753 Bytes
| use std::path::Path; | |
| use anyhow::{Context, Result}; | |
| use bstr::ByteSlice; | |
| impl crate::ForgeFS { | |
| pub async fn read_utf8<T: AsRef<Path>>(path: T) -> Result<String> { | |
| Self::read(path) | |
| .await | |
| .map(|bytes| bytes.to_str_lossy().to_string()) | |
| } | |
| pub async fn read<T: AsRef<Path>>(path: T) -> Result<Vec<u8>> { | |
| tokio::fs::read(path.as_ref()) | |
| .await | |
| .with_context(|| format!("Failed to read file {}", path.as_ref().display())) | |
| } | |
| pub async fn read_to_string<T: AsRef<Path>>(path: T) -> Result<String> { | |
| tokio::fs::read_to_string(path.as_ref()) | |
| .await | |
| .with_context(|| format!("Failed to read file as string {}", path.as_ref().display())) | |
| } | |
| } | |