public override int Read(byte[] buffer, int offset, int count) { int num = base.Read(buffer, offset, count); if (_cachedBytes < _cacheLimit) { int val = _cacheLimit - _cachedBytes; int num2 = Math.Min(num, val); byte[] array = new byte[num2]; Array.Copy(buffer, offset, array, 0, num2); AllReadBytes.AddRange(array); _cachedBytes += num2; } return(num); }
private void UpdateCacheAfterReading(byte[] buffer, int offset, int numberOfBytesRead) { // Limit the cached bytes to _cacheLimit if (_cacheLimit.HasValue) { if (_cachedBytes < _cacheLimit.Value) { int remainingBytes = _cacheLimit.Value - _cachedBytes; int bytesToCache = Math.Min(numberOfBytesRead, remainingBytes); var readBytes = new byte[bytesToCache]; System.Array.Copy(buffer, offset, readBytes, 0, bytesToCache); AllReadBytes.AddRange(readBytes); _cachedBytes += bytesToCache; } } else { var readBytes = new byte[numberOfBytesRead]; System.Array.Copy(buffer, offset, readBytes, 0, numberOfBytesRead); AllReadBytes.AddRange(readBytes); } }