use std::io::Error;
use std::path::Path;
use crate::client::Result;
use tokio::fs::File;
use tokio_stream::Stream;
use tokio_util::codec::{BytesCodec, FramedRead};
use tracing::instrument;
pub async fn raw<P: AsRef<Path>>(
file_path: P,
) -> Result<impl Stream<Item = std::result::Result<bytes::BytesMut, Error>>> {
let file = File::open(file_path).await?;
Ok(FramedRead::new(file, BytesCodec::new()))
}
#[instrument(level = "trace", skip(file_path), fields(path = %file_path.as_ref().display()))]
pub async fn toml<T>(file_path: impl AsRef<Path>) -> Result<T>
where
T: serde::de::DeserializeOwned,
{
let data = tokio::fs::read(file_path).await?;
Ok(toml::from_slice::<T>(&data)?)
}