Redzen.IO.MemoryBlockStream.WriteInner C# (CSharp) Method

WriteInner() private method

Write bytes into the memory stream, starting at the specified block index and intra-block offset.
private WriteInner ( byte buff, int offset, int count, int blockIdx, int blockOffset ) : void
buff byte
offset int
count int
blockIdx int
blockOffset int
return void
        private void WriteInner(byte[] buff, int offset, int count, int blockIdx, int blockOffset)
        {
            int remaining = count;
            int srcOffset = offset;
            int blkIdx = blockIdx;
            int blkOffset = blockOffset;

            for(;;)
            {
                // Get handle on target block.
                byte[] blk = _blockList[blkIdx];

                // Determine how many bytes to write into this block.
                int copyCount = Math.Min(_blockSize - blkOffset, remaining);

                // Write bytes into the block.
                Array.Copy(buff, srcOffset, blk, blkOffset, copyCount);

                // Test for completion.
                remaining -= copyCount;
                if(0 == remaining)
                {   // All bytes have been copied.
                    break;
                }

                // Update state.
                srcOffset += copyCount;
                blkIdx++;
                blkOffset++;
                blkOffset = 0;
            }

            _position += count;
            if(_position > _length) {
                _length = _position;
            }
        }