[Haskell-cafe] invalid character encoding

Ross Paterson ross at soi.city.ac.uk
Tue Mar 15 05:44:28 EST 2005

On Mon, Mar 14, 2005 at 07:38:09PM -0600, John Goerzen wrote:
> I've got some gzip (and Ian Lynagh's Inflate) code that breaks under
> the new hugs with:
>  <handle>: IO.getContents: protocol error (invalid character encoding)
> What is going on, and how can I fix it?

A Haskell 98 Handle is a character stream, and doesn't support binary
I/O.  This would have bitten you sooner or later on systems that do CRLF
conversion, but Hugs is now much stricter, because character streams now
use the encoding determined by the current locale (for the C locale, that
means ASCII only).

You can select binary I/O using the openBinaryFile and hSetBinaryMode
functions from System.IO.  After that, the Chars you get from that Handle
are actually bytes.

More information about the Haskell-Cafe mailing list