#temporary-files #tokio #temp

async-tempfile

Automatically deleted async I/O temporary files

5 releases (breaking)

0.5.0 Dec 6, 2023
0.4.0 Jun 16, 2023
0.3.0 Jun 12, 2023
0.2.0 Oct 22, 2022
0.1.0 Oct 22, 2022

#178 in Asynchronous

Download history 3354/week @ 2023-12-18 1819/week @ 2023-12-25 2910/week @ 2024-01-01 3905/week @ 2024-01-08 3768/week @ 2024-01-15 3667/week @ 2024-01-22 3419/week @ 2024-01-29 3757/week @ 2024-02-05 4475/week @ 2024-02-12 4498/week @ 2024-02-19 4644/week @ 2024-02-26 4839/week @ 2024-03-04 5043/week @ 2024-03-11 4702/week @ 2024-03-18 4215/week @ 2024-03-25 4337/week @ 2024-04-01

18,446 downloads per month
Used in 2 crates

MIT license

22KB
296 lines

async-tempfile

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());
}

lib.rs:

async-tempfile

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());
}

Features

  • uuid - (Default) Enables random file name generation based on the uuid crate. Provides the new and new_in, as well as the new_with_uuid* group of methods.

Dependencies

~2–3MB
~47K SLoC