internal void AddBytes(byte[] data, int offset, int length) { if (_completed) { throw new InvalidOperationException(); } if (length <= 0) { return; } if (_file == null) { // fits in the existing _data if (_length + length <= _data.Length) { Array.Copy(data, offset, _data, _length, length); _length += length; return; } // doesn't fit in _data but still under threshold // possible if content-length is -1, or when filtering if (_length + length <= _fileThreshold) { byte[] newData = new byte[_fileThreshold]; if (_length > 0) { Array.Copy(_data, 0, newData, 0, _length); } Array.Copy(data, offset, newData, _length, length); _data = newData; _length += length; return; } // need to convert to file _file = new TempFile(); _file.AddBytes(_data, 0, _length); } // using file _file.AddBytes(data, offset, length); _length += length; }