/// <inheritdoc /> public override int Read(byte[] buffer, int offset, int count) { if (_endOfStream) { return(0); } if (!HasData) // if all decoded data has been returned to the reader // go for a new portion { var inputCount = _underlyingStream.Read(_inputBuffer, 0, _inputBuffer.Length); if (0 == inputCount) { _endOfStream = true; return(0); } // push the new data to the pipe which is putting the output to _decodeBuffer _decodePipe.FeedFragment(Encoding.UTF8.GetString(_inputBuffer, 0, inputCount)); } var remainingLength = _decodeDataLength - _decodeOffset; var readingLength = Math.Min(remainingLength, count); Array.Copy(_decodeBuffer, _decodeOffset, buffer, offset, readingLength); _decodeOffset += readingLength; return(readingLength); }
/// <inheritdoc /> public override void Write(byte[] buffer, int offset, int count) { var bytes = new byte[count]; Array.Copy(buffer, offset, bytes, 0, count); var encoded = Encoding.UTF8.GetString(bytes); _decodePipe.FeedFragment(encoded); }