binary files in haskell

Sven Panne
Sat, 27 Jan 2001 18:35:49 +0100

[ Seems I *can't* mail in a sane way anymore, so please excuse my last
  half-baked one. But at least I've learned now that Ctrl-RET means
  "send immediately" in Netscape. Great idea! Here my next try... ]

Timmy Douglas wrote:
> I was wondering if anyone here has a solution for writing binary files
> that works in hugs and ghc that doesn't require getting libs.

I dont' know exactly about the current status of Hugs' libs, but I fear
the answer to your question is "no".

> I looked at this page:
> [...]

... and that was exactly the right place, see section "Bulk transfers":

   hGetBuf       :: Handle -> Addr -> Int -> IO Int
   hGetBufFull   :: Handle -> Addr -> Int -> IO Int

   hPutBuf       :: Handle -> Addr -> Int -> IO Int
   hPutBufFull   :: Handle -> Addr -> Int -> IO ()

These action read/write a given amount of bytes to/from a buffer. There
hasn't been much consensus about a higher level interface yet, but you
can have a look at my variant sitting on top of this:

Not the nicest and most efficient code on earth, but it should be enough
to get the idea. Note that in more recent (CVS) versions of GHC, `Addr'
(which is deprecated now) has been replaced by `Ptr a'.

Any ideas & suggestions for a good binary I/O interface are highly welcome!

   Sven "The Typo" P.