Awesome Conferences

Easily read UTF16-encoded files from Go

A program I wrote that worked for quite some time started failing. It turns out someone tried to use it to process a file with text encoded as UTF16. The file came from a Windows system and, considering things like UoW, this situation is just going to start happening more frequently.

Golang has a great package for dealing with various UTF encodings. That said, it still took me a few hours to figure out how to make an equivalent of ioutil.ReadFile(). I wrapped up what I learned and made it into a module. Everything should just work like magic.

  • Instead of using os.Open(), use utfutil.OpenFile().
  • Instead of ioutil.ReadFile(), use utfutil.ReadFile().

The module is available on Github: https://github.com/TomOnTime/utfutil

Posted by Tom Limoncelli in Technical Tips

Credits