#tempfile #filesystem #tmpfile

tempfile

A library for managing temporary files and directories

32 releases (stable)

3.0.7 Feb 17, 2019
3.0.5 Nov 26, 2018
3.0.3 Jul 17, 2018
3.0.0 Mar 25, 2018
0.5.1 May 22, 2015

#2 in Filesystem

Download history 30840/week @ 2018-11-04 31609/week @ 2018-11-11 29774/week @ 2018-11-18 36786/week @ 2018-11-25 37625/week @ 2018-12-02 38550/week @ 2018-12-09 33762/week @ 2018-12-16 25370/week @ 2018-12-23 30956/week @ 2018-12-30 35326/week @ 2019-01-06 38264/week @ 2019-01-13 38418/week @ 2019-01-20 37643/week @ 2019-01-27 43941/week @ 2019-02-03 55367/week @ 2019-02-10

159,217 downloads per month
Used in 1,441 crates (336 directly)

MIT/Apache

68KB
825 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