2
Vote

BZip2InputStream.Read returns -1 instead of 0

description

According to documentation on Stream class, the Read method should return 0 if the end of the stream has been reached, and there's no single mention of -1 possibility. But BZip2InputStream returns -1 if EOF is encountered.

This breaks some code relying on 0 as the EOF. I believe that Stream.CopyTo(...) will break as it checks for 0 as EOF.

comments

meddingt wrote Jun 10, 2013 at 9:31 PM

This should have a higher impact than low. This has a large affect on any implementation assuming correct behavior, or supporting different base stream types.

meddingt wrote Jun 10, 2013 at 9:32 PM

return (destOffset == offset) ? -1 : (destOffset - offset);

dbrowne wrote Aug 14, 2013 at 6:15 PM

Plus one. This is an incorrect Stream implementation. Please fix.

dbrowne wrote Aug 14, 2013 at 6:18 PM

The impact here is that BZip2InputStream can't be copied using Stream.CopyTo or a boilerplate stream copying method, and can't be composed with TextReaders and such. Basically you have to copy the contents of the BZip2InputStream to an uncompressed MemoryStream of FileStream to do anything with it.

David