private void WriteToBuffer(byte[] array, ref int offset, ref int count) { int bytesToWrite = Math.Min(_bufferSize - _writePos, count); if (bytesToWrite <= 0) return; EnsureBufferAllocated(); Buffer.BlockCopy(array, offset, _buffer, _writePos, bytesToWrite); _writePos += bytesToWrite; count -= bytesToWrite; offset += bytesToWrite; }