#temporary-files #tokio #temp

async-tempfile

Automatically deleted async I/O temporary files

7 releases (breaking)

0.7.0 Feb 22, 2025
0.6.0 Jun 30, 2024
0.5.0 Dec 6, 2023
0.4.0 Jun 16, 2023
0.1.0 Oct 22, 2022

#134 in Filesystem

Download history 9369/week @ 2025-01-17 18065/week @ 2025-01-24 24975/week @ 2025-01-31 22107/week @ 2025-02-07 17688/week @ 2025-02-14 36236/week @ 2025-02-21 36532/week @ 2025-02-28 43357/week @ 2025-03-07 38212/week @ 2025-03-14 48951/week @ 2025-03-21 32675/week @ 2025-03-28 59027/week @ 2025-04-04 34807/week @ 2025-04-11 43143/week @ 2025-04-18 34304/week @ 2025-04-25 31252/week @ 2025-05-02

151,626 downloads per month
Used in 12 crates (9 directly)

MIT license

41KB
502 lines

async-tempfile

Crates.io Crates.io GitHub Workflow Status docs.rs codecov

Provides the TempFile struct, an asynchronous wrapper based on tokio::fs for temporary files that will be automatically deleted when the last reference to the struct is dropped.

use async_tempfile::TempFile;

#[tokio::main]
async fn main() {
    let parent = TempFile::new().await.unwrap();

    // The cloned reference will not delete the file when dropped.
    {
        let nested = parent.open_rw().await.unwrap();
        assert_eq!(nested.file_path(), parent.file_path());
        assert!(nested.file_path().is_file());
    }

    // The file still exists; it will be deleted when `parent` is dropped.
    assert!(parent.file_path().is_file());
}

Dependencies

~1.9–7.5MB
~45K SLoC