
Hi MailList Haskell-Cafe: Till now, which module / package / lib can i use to access binary file ? And is this easy to use in GHC ? Regards -------------- L.Guo 2007-05-24

leaveye.guo:
Hi MailList Haskell-Cafe:
Till now, which module / package / lib can i use to access binary file ? And is this easy to use in GHC ?
Data.Binary? Or perhaps just Data.ByteString, available on hackage, http://hackage.haskell.org/cgi-bin/hackage-scripts/package/binary-0.3 or in base. -- Don

Thanks for your suggestion, and sorry for the subject. I have read the introduction of Data.ByteString, it is helpful. And also, there is one problem left. When i read a binary file, data is truncated at the charactor EOF. Which function could do this work correctly ? ------------------ L.Guo 2007-05-24 ------------------------------------------------------------- 发件人:Donald Bruce Stewart 发送日期:2007-05-24 14:03:27 收件人:L.Guo 抄送:MailList Haskell-Cafe 主题:Re: [Haskell-cafe] (no subject) leaveye.guo:
Hi MailList Haskell-Cafe:
Till now, which module / package / lib can i use to access binary file ? And is this easy to use in GHC ?
Data.Binary? Or perhaps just Data.ByteString, available on hackage, http://hackage.haskell.org/cgi-bin/hackage-scripts/package/binary-0.3 or in base. -- Don

leaveye.guo:
Thanks for your suggestion, and sorry for the subject.
I have read the introduction of Data.ByteString, it is helpful.
And also, there is one problem left. When i read a binary file, data is truncated at the charactor EOF.
Which function could do this work correctly ?
Hmm. Do you have an example? -- Don

On Thu, May 24, 2007 at 02:38:05PM +0800, L.Guo wrote:
Thanks for your suggestion, and sorry for the subject.
I have read the introduction of Data.ByteString, it is helpful.
And also, there is one problem left. When i read a binary file, data is truncated at the charactor EOF.
You have to use readBinaryFile instead of readFile. I had the same trouble as well. I finally implemented accessing single characters in C and did use ffi because I didn't know haw to do this i haskell properly. ( using peek/poke functions 4 bytes got written (wihch is annotateted somewhere ) If you are interested I can sent you the modified ByteString package. If someone can tell me which haskell function to use to set a random char in a memory buffer I would be pleased .. Marc

marco-oweber:
On Thu, May 24, 2007 at 02:38:05PM +0800, L.Guo wrote:
Thanks for your suggestion, and sorry for the subject.
I have read the introduction of Data.ByteString, it is helpful.
And also, there is one problem left. When i read a binary file, data is truncated at the charactor EOF.
You have to use readBinaryFile instead of readFile. I had the same trouble as well.
I finally implemented accessing single characters in C and did use ffi because I didn't know haw to do this i haskell properly. ( using peek/poke functions 4 bytes got written (wihch is annotateted somewhere ) If you are interested I can sent you the modified ByteString package.
If someone can tell me which haskell function to use to set a random char in a memory buffer I would be pleased ..
'poke' or else use unboxed Word8 arrays Check the src for Data.ByteString for examples.

Sorry for not familiar to the email client. My system is WinXP, and using GHC 6.6. And is read from file. Data is truncated at the ^Z char. I just wrote one simple test code.
import IO
writeTest fn = do h <- openFile fn WriteMode mapM_ (\p -> hPutChar h (toEnum p::Char)) $ [0..255] ++ [0..255] hClose h
accessTest fn = do h <- openFile fn ReadMode s <- hGetContents h putStrLn . show . map fromEnum $ s hClose h
main = do writeTest "ttt" accessTest "ttt"
participants (4)
-
dons@cse.unsw.edu.au
-
Ketil Malde
-
L.Guo
-
Marc Weber