public static void ConsumeStreamBytes(Stream stream, long length)
{
const int bufferSize = 4096;
int bytesLeft = (int) length;
var buffer = new byte[bufferSize];
while (bytesLeft > 0)
{
int count = stream.Read(buffer, 0, Math.Min(buffer.Length, bytesLeft));
bytesLeft -= count;
}
}
}