Crates.io | file_cache |
lib.rs | file_cache |
version | 0.0.5 |
source | src |
created_at | 2022-07-12 09:04:29.52056 |
updated_at | 2022-07-25 08:44:54.182869 |
description | cache file open handle |
homepage | |
repository | https://github.com/rmw-lib/file_cache |
max_upload_size | |
id | 624279 |
size | 29,505 |
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(())
}