file_cache

Crates.iofile_cache
lib.rsfile_cache
version0.0.5
sourcesrc
created_at2022-07-12 09:04:29.52056
updated_at2022-07-25 08:44:54.182869
descriptioncache file open handle
homepage
repositoryhttps://github.com/rmw-lib/file_cache
max_upload_size
id624279
size29,505
gcxfd (gcxfd)

documentation

README

file_cache

cache file open handle

use example

./examples/main.rs

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(())
}
Commit count: 46

cargo fmt