Code:
/// <returns>The number of bytes read. Zero signals the end of stream</returns>public override int Read(byte[ buffer, int offset, int count) {
... if (eof) return -1;
... }
The comment reads zero, the return value is -1. I am using the LzwInputStream class to read text from a .Z file as follows:
using (FileStream f = new FileStream("somefile.txt.Z"))using (LzwInputStream l = new LzwInputStream(f))
using (TextReader tr = new StreamReader(l, Encoding.ASCII, true, 1024 * 1024)) { string line; line = tr.ReadLine(); while (line != null)
{
//Do stuff here...
line = tr.ReadLine(); }
}
The ReadLine method will throw an exception because the returned bytecount is negative. Changing the return value to zero fixes the issue and also matches the documentation.