Skip to main content

Module encoding

Module encoding 

Source
Expand description

Decode raw source bytes into a String.

PowerShell tooling on Windows often saves scripts as UTF-16, or as UTF-8 with a byte-order mark, so a parser that only accepts UTF-8 needs the bytes decoded and the BOM removed first. These helpers do that using only the standard library.

Functionsยง

decode_bytes
Decode source bytes into a String, detecting UTF-8 and UTF-16 (LE/BE) by BOM, with a NUL-byte heuristic for BOM-less UTF-16.
strip_bom
Remove a leading byte-order-mark character (U+FEFF) if present.