#tokio #temp #temporary-files

async-tempfile

Automatically deleted async I/O temporary files

4 releases (breaking)

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

#429 in Filesystem

Download history 385/week @ 2023-06-08 510/week @ 2023-06-15 287/week @ 2023-06-22 235/week @ 2023-06-29 296/week @ 2023-07-06 546/week @ 2023-07-13 352/week @ 2023-07-20 413/week @ 2023-07-27 223/week @ 2023-08-03 293/week @ 2023-08-10 457/week @ 2023-08-17 339/week @ 2023-08-24 278/week @ 2023-08-31 386/week @ 2023-09-07 409/week @ 2023-09-14 534/week @ 2023-09-21

1,680 downloads per month
Used in shared-files

MIT license

21KB
257 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

~3.5MB
~56K SLoC