如何检测文件的编码?

I'm trying figure out the encoding of a file on Windows using Go. Doing some research, I've found many recommendations for Mozilla's Charset Detectors (chardet), but they're hard to compile, and I'm not having any luck.

I've also found libguess, and it seems is widely used in Linux, but I can't make it work in Windows.

What's the best way to go about this? Is there a de-facto standard library to use with Go on Windows?

You might be interested in Enca, Extremely Naive Charset Analyzer. I guess you could try to read the file using all candidate encodings and compute how far each of the attempts is from a “standard” character frequency distribution for the language. Enca requires some language info, but I’m not sure if it uses this approach. (It’s just an idea, it might be horribly misguided.)

You can use python package: chardet.