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

ReadBytes() public method

Reads the specified number of bytes, returning them in a new byte array. If not enough bytes are available before the end of the stream, this method will return what is available.
public ReadBytes ( int count ) : byte[]
count int The number of bytes to read
return byte[]
        public byte[] ReadBytes(int count)
        {
            CheckDisposed();
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count");
            }
            byte[] ret = new byte[count];
            int index=0;
            while (index < count)
            {
                int read = stream.Read(ret, index, count-index);
                // Stream has finished half way through. That's fine, return what we've got.
                if (read==0)
                {
                    byte[] copy = new byte[index];
                    Buffer.BlockCopy(ret, 0, copy, 0, index);
                    return copy;
                }
                index += read;
            }
            return ret;
        }