11 Sep
2004
11 Sep
'04
4:12 p.m.
Ron de Bruijn wrote:
I would like to write and read binary files in Haskell. I saw the System.IO module, but you need a (Ptr a) value for using that, and I don't need positions. I only want to read a complete binary file and write another binary file.
You just need to open the files with System.IO.openBinaryFile instead of openFile (files opened with the latter will have automatic LF/CRLF translation on Windows). Converting between Chars and octets (i.e. Word8) is just a matter of: import Char (ord, chr) charToOctet :: Char -> Word8 charToOctet = fromIntegral . ord octetToChar :: Word8 -> Char octetToChar = chr . fromIntegral -- Glynn Clements <glynn.clements@virgin.net>