fix(sem): refuse a UTF-16 compact snapshot by naming its encoding

main

Commit

Suhaan Thayyil3d ago

The byte-order-mark skip this branch adds covers UTF-8-with-BOM, which is what Windows PowerShell 5.1 writes for Out-File/Set-Content -Encoding utf8. It is not what that shell's > writes: the default there is UTF-16LE, so on a stock Windows box the documented save-then-query flow still failed, with

which names neither the encoding nor anything the caller can do about it. Such a file cannot be salvaged by reading further, so it is refused up front, by name, pointing at --output.

The four-byte UTF-32 marks are matched before the two-byte UTF-16 ones, because the UTF-32LE mark begins with the UTF-16LE mark and would otherwise be reported as UTF-16LE; reversing that order fails exactly the UTF-32LE case. A stream too short to hold a mark, and an ordinary UTF-8 artifact with or without its BOM, are left alone, which the companion test pins in the other direction.

Also moves compactSnapshotUTF8BOM above DecodeCompactSnapshot's doc comment. Declared between the comment and the function, it took the comment for itself and left the exported function undocumented.