[Haskell-cafe] Binary IO

Bulat Ziganshin bulat.ziganshin at gmail.com
Sat Jun 24 03:03:39 EDT 2006


Hello jeff,

Saturday, June 24, 2006, 10:19:17 AM, you wrote:

> I would greatly appreciate it if someone could post a small example or two illustrating how to do
> binary IO in Haskell using the most widely used binary IO lib (if
> there is such a thing).  Failing that, I would
> appreciate a link to some Haskell code that does binary IO that I could study.

the most widely used is NewBinary lib. but nevertheless i suggest you
to use my own Streams library. it's close enough to NewBinary in overall
ideology, but simpler, easy to install and may become new standard in
this area because it has innumerous number of features

Download: http://www.haskell.org/library/Streams.tar.gz
Installation: run "make install"

with my lib, binary I/O can be performed using Handles. there
are just a number of new I/O operations what reads and writes words of
specified size:

main = do h <- openBinaryFile "test" ReadMode
          i <- getWord32le h
          j <- getWord8 h
          ....
          hout <- openBinaryFile "test" WriteMode
          putWord32le hout (1::Int)
          putWord8    hout (2::Int)
          ...

you can use all the Handle operations (hSeek, hFilesize and so on) and
even mix binary and text I/O. there are also features to define
operations that read and write whole data structures

library docs are still unfinished. i will send existing bits of
documentation to you via email. i plan to publish final docs at
http://haskell.org/haskellwiki/Library/AltBinary but at this moment
this page contains only feature list


-- 
Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com



More information about the Haskell-Cafe mailing list