Encode immediately in hPutStr and hPutChar
This means that decoding errors will be detected accurately, and can be caught and handled. Overall the implementation is simpler this way too. It does impose a performance hit on small hPutStrs, although larger hPutStrs seem to be unaffected. To compensate somewhat, I optimised hPutStrLn.
Showing with 196 additions and 236 deletions