2 unstable releases

Uses new Rust 2024

new 0.2.0 May 3, 2025
0.1.0 Mar 22, 2025

#833 in Encoding

Download history 82/week @ 2025-03-17 38/week @ 2025-03-24 5/week @ 2025-03-31 1/week @ 2025-04-07 61/week @ 2025-04-28

62 downloads per month

GPL-3.0 license

18KB
163 lines

Filename sanitizer.

Supported OS:

  • Windows
  • Linux (unix)
  • MAC

Given a filename, escape the filename so that it is allowed by the OS.

The main functions of this crate are escape_str and replace_escape 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 and replace_escape for more info.


filesan

crates.io donwloads

Filename sanitizer.

Given a filename, escape the filename so that it is allowed by OS. For more info and examples see documentation.

Dependencies

~105KB