MiscUtil.IO.EndianBinaryReader.TryReadInternal C# (CSharp) Method

TryReadInternal() private method

Reads the given number of bytes from the stream if possible, returning the number of bytes actually read, which may be less than requested if (and only if) the end of the stream is reached.
private TryReadInternal ( byte data, int size ) : int
data byte Buffer to read into
size int Number of bytes to read
return int
        int TryReadInternal(byte[] data, int size)
        {
            CheckDisposed();
            int index=0;
            while (index < size)
            {
                int read = stream.Read(data, index, size-index);
                if (read==0)
                {
                    return index;
                }
                index += read;
            }
            return index;
        }