#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 17392/week @ 2018-08-22 22678/week @ 2018-08-29 22268/week @ 2018-09-05 26706/week @ 2018-09-12 31862/week @ 2018-09-19 28547/week @ 2018-09-26 29658/week @ 2018-10-03 31047/week @ 2018-10-10 31640/week @ 2018-10-17 25709/week @ 2018-10-24 30227/week @ 2018-10-31 31003/week @ 2018-11-07 26269/week @ 2018-11-14

76,502 downloads per month
Used in 1,194 crates (247 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