MCPcopy Index your code
hub / github.com/Stebalien/tempfile

github.com/Stebalien/tempfile @v3.27.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v3.27.0 ↗ · + Follow
216 symbols 771 edges 19 files 56 documented · 26% 6 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

tempfile

Crate 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.63.0

Add this to your Cargo.toml:

[dependencies]
tempfile = "3"

Supported Platforms

This crate supports all major operating systems:

  • Linux
  • Android
  • MacOS
  • Windows
  • FreeBSD (likely other BSDs but we don't have CI for them)
  • RedoxOS
  • Wasm (build and link only, Wasm doesn't have a filesystem)
  • WASI P1 & P2.

However:

  • Android, RedoxOS, Wasm, and WASI targets all require the latest stable rust compiler.
  • WASI P1/P2 does not define a default temporary directory. You'll need to explicitly call tempfile::env::override_temp_dir with a valid directory or temporary file creation will panic on this platform.
  • WASI P1/P2 does not have file permissions.
  • You may need to override the temporary directory in Android as well to point at your application's per-app cache directory.

Example

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);
}

Extension points exported contracts — how you extend this code

IoResultExt (Interface)
(no doc) [1 implementers]
src/error.rs

Core symbols most depended-on inside this repo

path
called by 33
src/dir/mod.rs
with_err_path
called by 29
src/error.rs
configure_wasi_temp_dir
called by 28
tests/namedtempfile.rs
path
called by 23
src/file/mod.rs
seek
called by 17
src/spooled.rs
as_file
called by 16
src/file/mod.rs
configure_wasi_temp_dir
called by 16
tests/spooled.rs
read_to_string
called by 15
src/spooled.rs

Shape

Function 112
Method 92
Class 10
Enum 1
Interface 1

Languages

Rust100%

Modules by API surface

src/file/mod.rs49 symbols
tests/namedtempfile.rs39 symbols
tests/spooled.rs25 symbols
src/spooled.rs21 symbols
src/dir/mod.rs18 symbols
src/lib.rs16 symbols
tests/tempdir.rs12 symbols
src/file/imp/windows.rs7 symbols
src/file/imp/unix.rs7 symbols
src/file/imp/other.rs6 symbols
src/error.rs5 symbols
tests/tempfile.rs3 symbols

For agents

$ claude mcp add tempfile \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact