public override int Read(byte[] buffer, int offset, int count)
{
int bytesToRead = count;
// Need to limit the # of bytes returned, if the stream is intended to have a definite length.
// This is especially useful when returning a stream for the uncompressed data directly to the
// application. The app won't necessarily read only the UncompressedSize number of bytes.
// For example wrapping the stream returned from OpenReader() into a StreadReader() and
// calling ReadToEnd() on it, We can "over-read" the zip data and get a corrupt string.
// The length limits that, prevents that problem.
if (_length != 0) {
if (_Crc32.TotalBytesRead >= _length)
return 0; // EOF
Int64 bytesRemaining = _length - _Crc32.TotalBytesRead;
if (bytesRemaining < count)
bytesToRead = (int)bytesRemaining;
}
int n = _InnerStream.Read (buffer, offset, bytesToRead);
if (n > 0)
_Crc32.SlurpBlock (buffer, offset, n);
return n;
}