[Haskell-cafe] two problems with Data.Binary and Data.ByteString

Don Stewart dons at galois.com
Wed Aug 13 23:24:02 EDT 2008

> On Wed, Aug 13, 2008 at 5:39 PM, Tim Newsham <newsham at lava.net> wrote:
> > So am I understanding you correctly that you believe this is not
> > a bug?  That the use Data.Binary.decodeFile function leaks a file
> > descriptor and this is proper behavior?
> I think he might be saying that decodeFile is not the place for
> checking this condition. I will put words in his mouth and say that
> checking for EOF after a decode is the responsibility of the
> application code, because the lower level cannot possibly know whether
> it makes sense for there to be residual data in the ByteString. There
> are plenty of file formats that consist of back-to-back concatenated
> chunks of data, in which reading just one chunk does not by any means
> require that a file can only contain one.


This particular condition -- that encode should consume exactly the
amount of data in the input file, and be sitting on EOF at the end -- is
application dependent.

That said, there's an argument to be made that the wrapper, decodeFile,
could reasonable assume this is the most common case.

-- Don

More information about the Haskell-Cafe mailing list