Add support for UTF-8 with BOM encoding

encode() does not support utf-8 with BOM. Some text editors save in it.
Merge pull request #56 from qrohlf/upstream

Add support for UTF-8 with BOM encoding