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;
}