/// <summary> /// Read bytes from stream, reading and joining chunks as needed. /// </summary> public override int Read(byte[] buffer, int offset, int count) { if (count > _buffer.Available() && !_complete) { var more = ReadNextChunk(); _buffer.UnRead(more, 0, more.Length); } return(_buffer.Read(buffer, offset, count)); }
/// <summary> /// Push data back onto the buffer, changing the Position /// and allowing the data to be read again. /// /// If the underlying stream supports seeking, a seek-back will /// be used instead. /// </summary> /// <param name="buffer">buffer used for matching 'Read' call</param> /// <param name="offset">offset used for matching 'Read' call</param> /// <param name="length">length *returned* by matching 'Read' call</param> public void UnRead(byte[] buffer, int offset, int length) { if (_baseStream.CanSeek) { _position = _baseStream.Seek(-length, SeekOrigin.Current); } else { _pushbackBuffer.UnRead(buffer, offset, length); _position -= length; } }