in src/RecyclableMemoryStream.cs [1045:1083]
public void Write(ReadOnlySpan<byte> source)
#else
public override void Write(ReadOnlySpan<byte> source)
#endif
{
this.CheckDisposed();
int blockSize = this.memoryManager.BlockSize;
long end = (long)this.position + source.Length;
this.EnsureCapacity(end);
if (this.largeBuffer == null)
{
var blockAndOffset = this.GetBlockAndRelativeOffset(this.position);
while (source.Length > 0)
{
byte[] currentBlock = this.blocks[blockAndOffset.Block];
int remainingInBlock = blockSize - blockAndOffset.Offset;
int amountToWriteInBlock = Math.Min(remainingInBlock, source.Length);
source.Slice(0, amountToWriteInBlock)
.CopyTo(currentBlock.AsSpan(blockAndOffset.Offset));
source = source.Slice(amountToWriteInBlock);
++blockAndOffset.Block;
blockAndOffset.Offset = 0;
}
}
else
{
source.CopyTo(this.largeBuffer.AsSpan((int)this.position));
}
this.position = end;
this.length = Math.Max(this.position, this.length);
}