4 releases
0.0.5 | Jul 25, 2022 |
---|---|
0.0.4 | Jul 25, 2022 |
0.0.3 | Jul 12, 2022 |
0.0.2 | Jul 12, 2022 |
#26 in #open-file
10KB
file_cache
cache file open handle
use example
use anyhow::Result;
use async_std::io::{prelude::SeekExt, ReadExt, SeekFrom};
use file_cache::FileCache;
async fn get(cache: &mut FileCache) -> Result<()> {
let mut path = std::env::current_exe()?;
(0..4).for_each(|_| {
path.pop();
});
let path = path.join("Cargo.toml").display().to_string();
let host = cache.get(path).await?;
let mut host = host.value();
host.seek(SeekFrom::Start(0)).await?;
let mut out = [0u8; 1024];
let n = host.read(&mut out).await?;
println!("{}", std::str::from_utf8(&out[..n])?);
dbg!(n);
Ok(())
}
#[async_std::main]
async fn main() -> Result<()> {
let mut cache = FileCache::new(2048)?;
get(&mut cache).await?;
Ok(())
}
Dependencies
~8–17MB
~246K SLoC