#filename #sanitizer

bin+lib sanitize-filename

A simple filename sanitizer, based on Node's sanitize-filename

5 releases (3 breaking)

Uses old Rust 2015

0.4.0 May 7, 2022
0.3.0 Oct 18, 2020
0.2.1 Oct 24, 2018
0.2.0 Oct 24, 2018
0.1.0 Oct 24, 2018

#121 in Parser implementations

Download history 10198/week @ 2022-12-04 11286/week @ 2022-12-11 8204/week @ 2022-12-18 5188/week @ 2022-12-25 8091/week @ 2023-01-01 10115/week @ 2023-01-08 11522/week @ 2023-01-15 12071/week @ 2023-01-22 14231/week @ 2023-01-29 13524/week @ 2023-02-05 14651/week @ 2023-02-12 14488/week @ 2023-02-19 17480/week @ 2023-02-26 16214/week @ 2023-03-05 14817/week @ 2023-03-12 15514/week @ 2023-03-19

65,236 downloads per month
Used in 60 crates (38 directly)

MIT license

11KB
305 lines

sanitize-filename

A basic filename sanitizer, based on Node's sanitize-filename.

Use like:

extern crate sanitize_filename;

fn main() {
    println!("{}", sanitize_filename::sanitize("some-user-defined/../../../string"));
    // prints some-user-defined......string
}

You can also configure a few basic options:

let options = sanitize_filename::Options {
    truncate: true, // true by default, truncates to 255 bytes
    windows: true, // default value depends on the OS, removes reserved names like `con` from start of strings on Windows
    replacement: "" // str to replace sanitized chars/strings
};

let sanitized = sanitize_filename::sanitize_with_options("some-user-defined/../../../string", options);

Also provides a basic command line binary. Use like:

cargo install sanitize-filename
sanitize-filename my_filename.txt
Pass a file name to clean to the program (also reads STDIN)

FLAGS:
    -r, --replace <r>          Replacement characters
    --windows, --no-windows    Whether to handle filenames for Windows
    --truncate, --no-truncate  Whether to truncate file names to 255 bytes

Dependencies

~0.9–1.3MB
~37K SLoC