RE: [Haskell-cafe] Re: Writing binary files?

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' ... 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 () After all, how can you 'normalise' a filename to a standard encoding if you don't have a function to do so. Infact if you encounter a server with an encoding you have no converter for, you have no choice but to treat it as raw bytes? Keean.

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'
Yes. 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
participants (2)
-
Glynn Clements
-
MR K P SCHUPKE