tempfile
A secure, cross-platform Rust library for temporary files and directories that clean up automatically on drop.
Repository Health
Technical Analysis
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. NamedTempFileandTempDirtypes with RAII cleanup, plus aBuilderfor 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 59 apps in this directory
abtop
Developer Tools · Monitoring
Like htop, but for your AI coding agents — monitor Claude Code, Codex CLI, and OpenCode sessions, tokens, context windows, rate limits, and orphan ports all from one terminal screen.
AFFiNE
Productivity · Project Management · Note Taking
Write, draw, and plan in one infinite canvas — the open-source alternative to Notion and Miro that keeps your data yours.
Anarlog
Note Taking · AI Assistants · Productivity
Anarlog is an open-source, local-first AI meeting notetaker that records, transcribes, and summarizes meetings entirely on your device — no cloud lock-in, no mandatory account, and every note saved as a plain markdown file you own forever.
AppFlowy
Productivity · Project Management · Collaboration
The open-source AI workspace that puts your data, your rules — with local LLMs, CRDT collaboration, and full self-hosting built in.
Arroyo
Data Engineering · Analytics
A distributed stream processing engine written in Rust that lets you write SQL to run stateful, real-time computations over data streams with subsecond results.
BrowserOS
Browser · AI Assistants
The open-source agentic Chromium browser with native AI agents, MCP server, and visual workflow automation — your data never leaves your machine.
Cameleer
AI Agents
A local-first desktop workspace for managing AI agents in an enterprise-style workflow — agent directory, Kanban task tracking, workspace chat, and a full runtime/audit log of agent actions and tool approvals.
Cap
Team Chat · Video Conferencing
Open source Loom alternative with GPU-accelerated recording, instant share links, AI summaries, and full self-hosting via Docker Compose.
claw-code
AI Agents · AI Code Assistants
A Rust-built CLI agent harness for Claude AI with persistent sessions, MCP tool integration, plugin hooks, and multi-provider support — designed to run autonomous coding workflows without human babysitting.