#tempfile #filesystem #tmpfile

tempfile

A library for managing temporary files and directories

33 releases (stable)

3.0.8 May 19, 2019
3.0.7 Feb 17, 2019
3.0.5 Nov 26, 2018
3.0.3 Jul 17, 2018
0.5.1 May 22, 2015

#3 in Filesystem

Download history 43941/week @ 2019-02-03 55367/week @ 2019-02-10 54076/week @ 2019-02-17 55861/week @ 2019-02-24 51248/week @ 2019-03-03 51655/week @ 2019-03-10 49295/week @ 2019-03-17 44702/week @ 2019-03-24 50330/week @ 2019-03-31 55747/week @ 2019-04-07 49445/week @ 2019-04-14 48071/week @ 2019-04-21 47340/week @ 2019-04-28 50283/week @ 2019-05-05 54774/week @ 2019-05-12

217,080 downloads per month
Used in 1,566 crates (392 directly)

MIT/Apache

71KB
869 lines

tempfile

Crate Build Status Build status

A secure, cross-platform, temporary file library for Rust. 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.24.0

Add this to your Cargo.toml:

[dependencies]
tempfile = "3"

...and this to your crate root:

extern crate tempfile;

Example

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

fn main() {
    // Write
    let mut tmpfile: File = 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);
}

Dependencies

~1MB
~12K SLoC