bug in hGetPS?

David Roundy droundy@abridgegame.org
Sat, 26 Apr 2003 09:26:23 -0400


I'm not sure if this counts as a bug or a feature...

If hGetPS h len encounters an EOF before len, it returns a PackedString
containing the remainder of the file.  However, if h is already at the end
of the file, an exception is raised rather than returning an empty string.
To me this is rather counter-intuitive.  Since hGetPS already has one way
of flagging the EOF condition (returning a string shorter than len), I
would prefer to be able (for example) to simply copy a file by a loop such
as:

cp h1 h2 = do ps <- hGetPS h1 buflen
              hPutPS h2 ps
              if lengthPS ps == buflen then cp h1 h2 else return ()

I know I could just as easily write the same code as:

cp h1 h2 = do ps <- hGetPS h1 buflen
              hPutPS h2 ps
              eof <- hIsEOF h1
              if not eof then cp h1 h2 else return ()

but since the first should be as fast as the second, I don't see why it
shouldn't be made safe.
-- 
David Roundy
http://www.abridgegame.org