#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

#4 in Filesystem

Download history 26767/week @ 2018-12-20 27379/week @ 2018-12-27 37475/week @ 2019-01-03 35942/week @ 2019-01-10 38679/week @ 2019-01-17 38049/week @ 2019-01-24 38342/week @ 2019-01-31 53556/week @ 2019-02-07 54670/week @ 2019-02-14 55247/week @ 2019-02-21 53438/week @ 2019-02-28 52096/week @ 2019-03-07 50240/week @ 2019-03-14 45749/week @ 2019-03-21 47887/week @ 2019-03-28

197,455 downloads per month
Used in 1,486 crates (360 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