tempfile

A secure, cross-platform Rust library for temporary files and directories that clean up automatically on drop.

Library
Cargo
v3.27.0
1,468 stars
MIT OR Apache-2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
68 /100 Good
Development Activity 72
Maintenance 32
Community 68
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
90 /100 Excellent
Architecture 90
Code Quality 92
Innovation 88
Learning Curve 90

tempfile is a battle-tested Rust crate for creating temporary files and directories that are automatically removed when they are no longer referenced. It handles the surprisingly hard parts of temporary storage securely and portably: unpredictable random file names, private-by-default permissions, and reliable cleanup via RAII destructors or the operating system itself.

Beyond simple scratch files, the library lets you open multiple independent handles to the same unnamed temporary file, name temporary files so they can be passed to other processes by path, and spool data in memory until it grows large enough to warrant spilling to disk. It supports every major platform, from Linux, macOS, and Windows to the BSDs, Illumos, Redox, and WASI.

What You Get

  • Unnamed temporary files via tempfile() that the OS removes once the last handle closes, with no reliance on destructors running.
  • NamedTempFile and TempDir types with RAII cleanup, plus a Builder for customizing prefix, suffix, randomness, permissions, and directory.
  • A spooled_tempfile() buffer that stays in memory until it exceeds a threshold, then transparently spills to a real temporary file.
  • Secure defaults: private file permissions, 6 random characters per name, and re-seeding from system randomness after repeated collisions.
  • Broad platform coverage including Linux, macOS, Windows, the BSDs, Illumos, Redox, and WASI.

Common Use Cases

  • Buffering large or streamed data to disk during processing without leaking files.
  • Providing isolated scratch directories for test fixtures that are torn down automatically.
  • Writing a file atomically by staging it in a temporary location and persisting it into place on success.

Under The Hood

Architecture — The public surface in src/lib.rs (a Builder plus free functions like tempfile(), tempdir(), and spooled_tempfile()) delegates to a shared name-generation and retry core in src/util.rs, whose create_helper forks a fastrand RNG, builds absolute paths, and retries on AlreadyExists/AddrInUse collisions. Platform behavior is isolated behind per-OS implementation modules under src/file/imp/ (unix.rs, windows.rs, other.rs) and src/dir/imp/, so the cross-cutting logic stays platform-agnostic while syscalls live in cfg-gated backends.

Tech Stack — Pure Rust (edition 2021, MSRV 1.63) with a deliberately minimal dependency set: fastrand for fast name randomness, once_cell for lazily-initialized globals, rustix for Unix/WASI filesystem syscalls, windows-sys for the Win32 storage APIs, and an optional getrandom (default-enabled) for secure RNG re-seeding. Version bounds are kept wide to preserve compatibility with Debian-stable toolchains.

Code Quality — The crate is mature and thoroughly tested, with a dedicated integration suite in tests/ covering tempfile, namedtempfile, tempdir, spooled, and env behaviors. Error handling is careful and explicit — collision kinds are matched precisely, paths are attached to errors via an IoResultExt helper, and security-sensitive decisions (re-seeding after three failures, absolute-path normalization) are documented inline. Naming is idiomatic and the module boundaries are clean.

API Design — The developer experience is excellent: one-line helpers cover the common cases while a fluent Builder exposes prefix, suffix, rand_bytes, permissions, append, and directory controls for the rest. Extensive rustdoc with runnable examples, a documented security model, and an explicit callout of the early-drop pitfall make the API both ergonomic and hard to misuse.

Used by 69 apps in this directory

TypeScript
73%
AGPL 3.0

Tolaria

Note Taking

19,917

A free, open-source, local-first desktop app for managing markdown knowledge bases on macOS, Windows, and Linux — for second brains, company docs, or AI assistant memory and procedures.

View details
81
Repo Health
71
Technical
68
Dependency
Built with
TypeScript 73%
Rust 13%
JavaScript 12%
Updated 2 weeks ago
Python
73%
Apache 2.0

Unsloth

AI Assistants · AI Development

76,886

Run and fine-tune LLMs, diffusion, audio and embedding models on your own hardware, from a native desktop app, a browser UI, or a Python library.

View details
89
Repo Health
83
Technical
70
Dependency
Built with
Python 73%
TypeScript 21%
Updated 1 weeks ago
Rust
50%
Apache 2.0

Vibe Kanban

AI Agents · AI Code Assistants · Project Management

28,209

A kanban board for planning work and dispatching Claude Code, Codex, Gemini CLI, and eight other coding agents into isolated git worktrees, then reviewing and merging their diffs from one UI.

View details
75
Repo Health
75
Technical
64
Dependency
Built with
Rust 50%
TypeScript 46%
Updated 2 weeks ago
TypeScript
95%
Apache 2.0

Void

AI Code Assistants · Automation · Code Editors

28,786

Open-source AI code editor with direct LLM integration and data privacy

View details
45
Repo Health
84
Technical
68
Dependency
Built with
TypeScript 95%
Updated 4 months ago
Python
65%
Apache 2.0

WrenAI

AI Agents · Analytics · Data Engineering

17,763

Open-source GenBI engine that lets AI agents turn natural-language questions into governed SQL, charts, and shareable dashboards across 20+ data sources — no vendor lock-in, no black-box prompts.

View details
90
Repo Health
91
Technical
69
Dependency
Built with
Python 65%
Rust 32%
Updated 2 weeks ago
TypeScript
41%
MIT

YuE2 Studio

Mcp · Music Audio

413

Windows desktop studio that runs the YuE2 song model on your own NVIDIA GPU: it writes an editable sheet-music score first, then sings it as a full song with vocals, offline, with covers, LoRA training and an MCP server for agents.

View details
71
Repo Health
83
Technical
76
Dependency
Built with
TypeScript 41%
Rust 36%
JavaScript 21%
Updated 6 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers