| Crates.io | crabcakes-async-spooled-tempfile |
| lib.rs | crabcakes-async-spooled-tempfile |
| version | 0.0.1 |
| created_at | 2025-10-06 03:06:28.408114+00 |
| updated_at | 2025-10-06 03:06:28.408114+00 |
| description | Asynchronous memory-then-disk spooled tempfile |
| homepage | https://github.com/yaleman/crabcakes |
| repository | https://github.com/yaleman/crabcakes |
| max_upload_size | |
| id | 1869695 |
| size | 32,227 |
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!
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"),
}