Skip to main content

Module raw_name

Module raw_name 

Source
Expand description

Byte-exact on-disk names through the &str filesystem API.

Unix filesystems store a name as bytes, not text. NeXTSTEP wrote its names in the 8-bit NeXTSTEP encoding (ASCII below 0x80; 0x80-0xFD are Latin letters and punctuation laid out unlike ISO 8859-1 — 0xF6 is u with a diaeresis, 0xBC a horizontal ellipsis; see Unicode’s VENDORS/NEXT/NEXTSTEP.TXT), and Japanese NeXTSTEP-J wrote EUC-JP. Neither is UTF-8, and which one a given disk used is not recorded anywhere, so a name cannot be transcoded safely — only carried.

The filesystem traits pass names as String, so undecodable bytes travel as placeholder characters: byte b becomes U+10FF00 + b, the last 256 code points of Supplementary Private Use Area-B, which no real name uses. decode turns on-disk bytes into such a name (valid UTF-8 runs are kept as text), and encode turns it back into the exact bytes, so a name read off one disk and written to another lands byte for byte. A host file whose name carries the placeholders (an earlier extract) re-imports the same way.

Functions§

decode
On-disk name bytes as a name: UTF-8 kept as text, every other byte a placeholder.
display
name with each placeholder shown as \xNN, for terminal output.
encode
The bytes to store for name: placeholders become their byte, everything else UTF-8.
raw_byte
The byte a placeholder stands for, or None for an ordinary character.