Revenj.Utility.ChunkedMemoryStream.Write C# (CSharp) Method

Write() public method

Write buffer to stream. Advances current position by count. Increases length if necessary. New blocks will be added as required. It's best to use buffer of size 8192
public Write ( byte buffer, int offset, int count ) : void
buffer byte provided bytes
offset int offset in bytes
count int total length
return void
        public override void Write(byte[] buffer, int offset, int count)
        {
            int cur = count;
            while (cur > 0)
            {
                var pos = CurrentPosition >> BlockShift;
                var off = CurrentPosition & BlockAnd;
                var min = BlockSize - off;
                if (cur < min)
                    min = cur;
                Buffer.BlockCopy(buffer, offset + count - cur, Blocks[pos], off, min);
                cur -= min;
                CurrentPosition += min;
                if (min == BlockSize - off && Blocks.Count == pos + 1)
                    Blocks.Add(new byte[BlockSize]);
            }
            if (CurrentPosition > TotalSize)
                TotalSize = CurrentPosition;
        }