#tempfile #filesystem #tmpfile

tempfile

A library for managing temporary files and directories

28 releases (stable)

3.0.3 Jul 17, 2018
3.0.1 Apr 18, 2018
3.0.0 Mar 25, 2018
2.2.0 Sep 27, 2017
0.5.1 May 22, 2015

#6 in Filesystem

Download history 14481/week @ 2018-05-27 18324/week @ 2018-06-03 17526/week @ 2018-06-10 16108/week @ 2018-06-17 17076/week @ 2018-06-24 18962/week @ 2018-07-01 18642/week @ 2018-07-08 20532/week @ 2018-07-15 23388/week @ 2018-07-22 21109/week @ 2018-07-29 24660/week @ 2018-08-05 23322/week @ 2018-08-12 19851/week @ 2018-08-19

76,502 downloads per month
Used in 674 crates (195 directly)

MIT/Apache

62KB
712 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.18.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
~11K SLoC