#temporary-files #async #spooled

async-spooled-tempfile

Asynchronous spooled temporary file

1 unstable release

new 0.1.0 Dec 11, 2024

#1054 in Filesystem

Download history 144/week @ 2024-12-09

144 downloads per month

Apache-2.0 OR MIT

16KB
283 lines

async-spooled-tempfile


Crate exposing an asynchronous version of the tempfile::SpooledTempFile structure provided by the tempfile crate.

Dependency

Add the following line to your Cargo.toml file:

[dependencies]
async-spooled-tempfile = "0.1.0"

Example

use async_spooled_tempfile::{SpooledData, SpooledTempFile};
use tokio::io::AsyncWriteExt;

#[tokio::main]
async fn main() {
    let mut sf = SpooledTempFile::new(10);

    sf.write_all(b"12345").await.unwrap();
    assert!(!sf.is_rolled());

    sf.write_all(b"6789abc").await.unwrap();
    assert!(sf.is_rolled());

    assert!(std::matches!(
        sf.into_inner().await,
        Ok(SpooledData::OnDisk(_file))
    ));
}

lib.rs:

Crate providing an asynchronous version of the tempfile::SpooledTempFile structure exposed by the tempfile crate.

Dependencies

~4–13MB
~158K SLoC