1 unstable release
Uses new Rust 2024
new 0.1.0 | Mar 22, 2025 |
---|
#658 in Filesystem
17KB
112 lines
filesan
Filename sanitizer.
Given a filename, escape the filename so that it is allowed by OS. For more info and examples see documentation.
Links
- Author: BonnyAD9
- GitHub: BonnyAD9/filesan
- Package: crates.io
- Documentation: docs.rs
- My Website: bonnyad9.github.io
lib.rs
:
Filename sanitizer.
Supported OS:
- Windows
- Linux (unix)
- MAC
Given a filename, escape the filename so that it is allowed by the OS.
The main function of this crate is escape_str
which will take string
as input, and return modified version that can be used as filename:
use filesan::{escape_str, Mode};
// Unix support
assert_eq!(
escape_str("\x00hello/the_re.txt:.", '_', Mode::UNIX),
"_00hello_2Fthe_5Fre.txt:."
);
// Windows support
assert_eq!(
escape_str("\x00hello/the_re.txt:.", '_', Mode::WINDOWS),
"_00hello_2Fthe_5Fre.txt_3A_2E"
);
// MACOS support
assert_eq!(
escape_str("\x00hello/the_re.txt:.", '_', Mode::MAC),
"_00hello_2Fthe_5Fre.txt_3A."
);
You can use Mode::SYSTEM
to get your current target system. See
documentation of escape_str
for more info.
Dependencies
~110KB