tempfs
tempfs is a lightweight Rust crate that provides utilities for managing temporary files and directories. It makes working with temporary resources easier by automatically cleaning up files and directories when they go out of scope. The crate offers a flexible API with optional support for features such as random name generation, memory mapping, and regex-based file filtering.
Features
-
Temporary Directory (
TempDir):
Create and manage a temporary directory whose contents are automatically removed when the directory is dropped. -
Temporary File (
TempFile):
Create temporary files with support for writing, reading, renaming, persisting, and even memory mapping (if enabled). -
Optional Feature Flags:
rand_gen: Enables random name generation for temporary files and directories. (Requires theranddependency.)mmap_support: Enables memory mapping of temporary files via thememmap2crate.regex_support: Enables regex-based filtering and searching of temporary files using theregexcrate.full: Activates all optional features at once.
Installation
Add tempfs to your Cargo.toml:
[]
= "0.7.5"
To enable one or more optional features, specify them like so:
[]
= "0.7.5"
= ["full"]
Usage
Below is a simple example demonstrating how to create a temporary directory and file:
use ;
use Write;
Advanced Usage
-
Random Naming:
If you enable therand_genfeature, you can use methods likeTempDir::randomandTempFile::new_randomto create temporary resources with random names. -
Regex-Based Filtering:
When theregex_supportfeature is enabled, you can filter temporary files usingTempDir::find_files_by_patternor its mutable counterpart. -
Memory Mapping:
With themmap_supportfeature enabled, you can create memory maps of temporary files usingTempFile::mmapandTempFile::mmap_mut.
Documentation
Full API documentation is available on docs.rs.
License
This project is dual licensed under the MIT and Apache 2.0 Licenses. See the MIT license and Apache license files for details.
Contributing
Contributions, issues, and feature requests are welcome! Please check the issues page for existing issues before creating new ones. Pull requests are also welcome.