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

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Wed Aug 13 21:58:22 EDT 2008


On Wed, 2008-08-13 at 12:02 -1000, Tim Newsham wrote:

> However, I think probably the real blame here should probably go
> to Data.Binary which doesn't attempt to check that it has consumed
> all of its input after doing a "decode".  If "decode" completes
> and there is unconsumed data, it should probably raise an error
> (it already raises errors for premature EOF).  There's no reason
> for it not to, since it does not provide the unconsumed data to
> the caller when its done, anyway...
> 
> Thoughts?

I think you're right. The Binary instances cannot and must not read more
than they need to, so that gives us the behaviour that we read exactly
the length of the file, but no more, and thus we never hit EOF, so we
don't close the file. So yes, decode should force the tail so that it
can indeed hit EOF.

Duncan



More information about the Haskell-Cafe mailing list