path_to_unicode_filename 0.1.1

The library encodes file path separators and common directory names, producing a reversible unicode string that can be used as a filename. It's useful in the case when you want to extract data or features from any file and store them in a specific directory.
Documentation
  • Coverage
  • 11.11%
    1 out of 9 items documented1 out of 6 items with examples
  • Size
  • Source code size: 38.9 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 258.3 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 13s Average build duration of successful builds.
  • all releases: 13s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • amachang/path_to_unicode_filename
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • amachang

GitHub Workflow Status (with event) docs.rs Crates.io Crates.io

path_to_unicode_filename

The library encodes file path separators and common directory names, producing a reversible unicode string that can be used as a filename. It's useful in the case when you want to extract data or features from any file and store them in a specific directory.

It replaces path chars as below:

  • chars \/:*?"<>| be replaced to full width alternative chars of unicode.
  • U+0000 be replaced to 〇.
  • a common directory, like home, documents, pictures, etc are replaced to a OS icon (🍎, 🐧, etc) and a directory icon (🏠, 📄, 🎨, etc).
  • chars replacements for others be replaced to twice-sequential chars itself

Examples

use path_to_unicode_filename::*;

// make a filename
assert_eq!(to_filename("/tmp/file.txt"), Ok("/tmp/file.txt".into()));
assert_eq!(to_filename("C:\\Users\\alice\\file.txt"), Ok("💠🏠alice\file.txt".into()));
assert_eq!(to_filename("/Users/alice/Documents/file.txt"), Ok("🍎📄alice/file.txt".into()));

// restore the filename to the original path
assert_eq!(to_path("/var/log/file.txt"), Ok("/var/log/file.txt".into()));
assert_eq!(to_path("🐧🥞sdcard001/file.txt"), Ok("/media/sdcard001/file.txt".into()));
assert_eq!(to_path("🍎🎨bob/file.png"), Ok("/Users/bob/Pictures/file.png".into()));

License: MIT OR Apache-2.0