crabcakes-async-spooled-tempfile

Crates.iocrabcakes-async-spooled-tempfile
lib.rscrabcakes-async-spooled-tempfile
version0.0.1
created_at2025-10-06 03:06:28.408114+00
updated_at2025-10-06 03:06:28.408114+00
descriptionAsynchronous memory-then-disk spooled tempfile
homepagehttps://github.com/yaleman/crabcakes
repositoryhttps://github.com/yaleman/crabcakes
max_upload_size
id1869695
size32,227
James Hodgkinson (yaleman)

documentation

README

crabcakes-async-spooled-tempfile

This'll keep the temporary file in memory until it hits a certain size, then spools to disk for further use. Uses tokio to get things done.

PRs and bugs welcome!

Example


let mut file = SpooledTempFile::new(100);
let data = vec![1u8; 200]; // Exceeds threshold
file.write_all(&data).await.unwrap();
file.flush().await.unwrap();

let spooled_data = file.into_inner().await.unwrap();
match spooled_data {
    SpooledData::OnDisk(mut f) => {
        use tokio::io::AsyncSeekExt;
        f.seek(SeekFrom::Start(0)).await.unwrap();
        let mut buf = Vec::new();
        f.read_to_end(&mut buf).await.unwrap();
        assert_eq!(buf.len(), 200);
    }
    SpooledData::InMemory(_) => panic!("Expected on-disk data"),
}
Commit count: 0

cargo fmt