public override int Read(byte[] buffer, int offset, int count)
{
// if we've no output and it was the special termination chunk,
// we're done otherwise fill the input buffer with enough data
// for the next chunk (or with whatever is left) and construct
// the chunk in the output buffer ready for streaming
if (_outputBufferPos == -1)
{
if (_wrappedStreamConsumed && _outputBufferIsTerminatingChunk)
return 0;
var bytesRead = FillInputBuffer();
ConstructOutputBufferChunk(bytesRead);
_outputBufferIsTerminatingChunk = (_wrappedStreamConsumed && bytesRead == 0);
}
var outputRemaining = _outputBufferDataLen - _outputBufferPos;
if (outputRemaining < count)
count = outputRemaining;
Buffer.BlockCopy(_outputBuffer, _outputBufferPos, buffer, offset, count);
_outputBufferPos += count;
if (_outputBufferPos >= _outputBufferDataLen)
_outputBufferPos = -1;
return count;
}