One of your questions answers the other: the BOM allows you to identify the exact UTF encoding used in the file.
Ideally, readText
would do this for you. Currently, it doesn't, so you'd have to implement it yourself.
I'd recommend using std.file.read
, casting the returned void[]
to a ubyte[]
, then looking at the first few bytes to see if they start with a BOM, then cast the result to the appropriate string type and convert it to a string
(using toUTF8
or to!string
).