private static byte[] ReadExactlyFast(Stream fromStream, byte[] intoBuffer, int startAtIndex, int bytesToRead)
{
var index = 0;
while (index < bytesToRead)
{
var read = fromStream.Read(intoBuffer, startAtIndex + index, bytesToRead - index);
if (read == 0)
{
throw new EndOfStreamException
(string.Format("End of stream reached with {0} byte{1} left to read.",
bytesToRead - index,
bytesToRead - index == 1 ? "s" : ""));
}
index += read;
}
return intoBuffer;
}