System.StreamExtensions.ReadNoAlloc C# (CSharp) Method

ReadNoAlloc() public static method

public static ReadNoAlloc ( this stream, byte bytes, int offset, int count ) : void
stream this
bytes byte
offset int
count int
return void
        public static unsafe void ReadNoAlloc(this Stream stream, byte* bytes, int offset, int count)
        {
            var buffer = Buffer;
            int readCount = 0;
            int write = offset;
            int writeEnd = offset + count;
            while (write != writeEnd)
            {
                readCount = Math.Min(count, buffer.Length);
                stream.Read(buffer, 0, readCount);
                count -= readCount;
                for (int i = 0; i < readCount; ++i)
                {
                    Debug.Assert(write < writeEnd);
                    bytes[write++] = buffer[i];
                }
            }
        }