This is useful for avoiding crashing on "cdiff -l" (on Python 3) in https://github.com/myint/cppclean. Also handle unknown encodings gracefully rather than crashing.