[Haskell-cafe] Re: Writing binary files?
glynn.clements at virgin.net
Thu Sep 16 06:24:51 EDT 2004
MR K P SCHUPKE wrote:
> >E.g. what happens if you call getDirectoryContents for a directory
> >which contains filenames which aren't valid in the current encoding?
> Surely this shows the problem with the idea of a 'current encoding'
In case I haven't already made this clear, my argument is essentially
that it's the API which is broken, rather than the implementations.
> ... You could be reading files from two remote servers each using
> different encodings...
> So you could have read and write raw [Word8] and read and write char,
> somehting like:
> readWithEncoder :: ([Word8] -> [Char]) -> IO [Char]
> writeWithEncoder :: ([Char] -> [Word8]) -> [Char] -> IO ()
In the general case, it needs to be a bit more complex than that, in
order to handle stateful encodings (e.g. ISO-2022), or to handle
decoding multi-byte encodings (e.g. UTF-8) in chunks. Unfortunately,
the iconv interface doesn't allow the encoder state to be extracted,
so a generic iconv-based converter would have to be in the IO monad.
Glynn Clements <glynn.clements at virgin.net>
More information about the Haskell-Cafe