#temporary-files #temp-dir #file-path #directory #utf-8 #camino

camino-tempfile

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

3 stable releases

1.1.1 Nov 28, 2023
1.0.3 Nov 28, 2023
1.0.2 Apr 24, 2023

#255 in Filesystem

Download history 14992/week @ 2024-07-23 14343/week @ 2024-07-30 14924/week @ 2024-08-06 17667/week @ 2024-08-13 16216/week @ 2024-08-20 19279/week @ 2024-08-27 18401/week @ 2024-09-03 15779/week @ 2024-09-10 17935/week @ 2024-09-17 21033/week @ 2024-09-24 22504/week @ 2024-10-01 21446/week @ 2024-10-08 19652/week @ 2024-10-15 19048/week @ 2024-10-22 21599/week @ 2024-10-29 24265/week @ 2024-11-05

88,998 downloads per month
Used in 27 crates (15 directly)

MIT/Apache

73KB
525 lines

camino-tempfile

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

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).

Documentation

Usage

Minimum required Rust version: 1.63.0

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

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

~1.7–9.5MB
~111K SLoC