#temporary-files #camino #temp-file

camino-tempfile

A library for managing temporary files and directories, with UTF-8 paths

5 stable releases

new 1.3.0 May 3, 2025
1.2.0 May 2, 2025
1.1.1 Nov 28, 2023
1.0.3 Nov 28, 2023
1.0.2 Apr 24, 2023

#220 in Filesystem

Download history 39188/week @ 2025-01-12 33686/week @ 2025-01-19 38436/week @ 2025-01-26 40244/week @ 2025-02-02 42790/week @ 2025-02-09 39770/week @ 2025-02-16 47340/week @ 2025-02-23 43551/week @ 2025-03-02 39857/week @ 2025-03-09 38173/week @ 2025-03-16 39696/week @ 2025-03-23 35520/week @ 2025-03-30 38344/week @ 2025-04-06 41453/week @ 2025-04-13 43920/week @ 2025-04-20 33767/week @ 2025-04-27

158,841 downloads per month
Used in 31 crates (15 directly)

MIT/Apache

78KB
543 lines

camino-tempfile

camino-tempfile on crates.io Documentation (latest release) Documentation (main) License (Apache 2.0) License (MIT)

A secure, cross-platform, temporary file library for Rust with UTF-8 paths.

This crate is a wrapper around tempfile that works with the Utf8Path and Utf8PathBuf types defined by camino. If your code mostly uses camino, it can be annoying to have to convert temporary paths to Utf8Path over and over again. This crate manages that for you.

In addition to creating temporary files, this library also allows users to securely open multiple independent references to the same temporary file (useful for consumer/producer patterns and surprisingly difficult to implement securely).

This crate closely mirrors tempfile's interface. For extensions that provide quality-of-life improvements such as the ability to create files easily, see camino-tempfile-ext.

Documentation

Usage

Add this to your Cargo.toml:

[dependencies]
camino-tempfile = "1"

Example

use std::fs::File;
use std::io::{Write, Read, Seek, SeekFrom};

fn main() {
    // Write
    let mut tmpfile: File = camino_tempfile::tempfile().unwrap();
    write!(tmpfile, "Hello World!").unwrap();

    // Seek to start
    tmpfile.seek(SeekFrom::Start(0)).unwrap();

    // Read
    let mut buf = String::new();
    tmpfile.read_to_string(&mut buf).unwrap();
    assert_eq!("Hello World!", buf);
}

Minimum supported Rust version (MSRV)

camino-tempfile's MSRV is Rust 1.74. At any time, at least the last 6 months of Rust releases will be supported.

License

This project is available under the terms of either the Apache 2.0 license or the MIT license.

Portions copied and adapted from tempfile and used under the MIT and Apache 2.0 licenses. tempfile is copyright 2015 Steven Allen and the tempfile authors.

Dependencies

~2–11MB
~130K SLoC