#async #facade #back-end #tokio #disk #fs

floppy-disk

async filesystem facade for rust!

17 releases

0.2.6 Jul 19, 2023
0.2.5 Jun 22, 2023
0.2.1 May 30, 2023
0.1.8 May 29, 2023
0.0.0 Mar 16, 2023

#548 in Filesystem

Download history 90/week @ 2024-07-20 49/week @ 2024-07-27 30/week @ 2024-08-03 58/week @ 2024-08-10 24/week @ 2024-08-17 38/week @ 2024-08-24 24/week @ 2024-08-31 31/week @ 2024-09-07 18/week @ 2024-09-14 36/week @ 2024-09-21 22/week @ 2024-09-28 1/week @ 2024-10-05 14/week @ 2024-10-12 62/week @ 2024-10-19 4/week @ 2024-10-26 4/week @ 2024-11-02

84 downloads per month
Used in 5 crates

MIT license

51KB
1.5K SLoC

floppy-disk

floppy disk is a WIP, async-only filesystem facade for Rust.

What?

Have you ever worked with std::fs? tokio::fs? Then you've probably realised that testing filesystem code is difficult and sometimes scary. Is that fs::remove_dir_all really safe to run?

The point of floppy disk is to fix this. Rather than always using the real filesystem, floppy disk lets you choose a backend for your filesystem access, via the FloppyDisk trait. Current implementations include in-memory and real filesystem via Tokio. This way, you can use the real filesystem when you need, but have your tests hit a fake in-memory filesystem instead.

Features

  • Pluggable filesystem backends
    • In-memory (WIP)
    • Tokio
  • Write-your-own with the FloppyDisk trait
  • Fully-async
    • Light evil involved

Caveats

  • floppy disk is a 0.x.y project! You probably don't want to use it in production.
  • async-only! There is some small bridging to sync code, like MemFile implementing Read/Write/Seek, but this is mostly a hack to make working with sync-only external libraries (ex. ar) easier.
  • in-memory fs may not be performant-enough

Example usage

floppy disk attempts to recreate the std::fs API 1:1, with the caveat of being async-only.

let fs = ...; // MemFloppyDisk::new() | TokioFloppyDisk::new()
fs.create_dir_all("/foo/bar").await?;
fs.write("/foo/bar/baz.txt", b"hello world").await?;
let contents = fs.read_to_string("/foo/bar/baz.txt").await?;
assert_eq!(contents, "hello world");

Passing a FloppyDisk around:

struct MyStruct<'a, F: FloppyDisk<'a>> {
    fs: F,
    _marker: PhantomData<&'a ()>,
}

async fn my_fn<'a, F: FloppyDisk<'a>> {
   // ...
}

Dependencies

~7–13MB
~162K SLoC