Byte sized code nuggets

Just a few pieces of C# code that someone might find usefull.

How to detect if a JPEG is progressive

If you need to be able to detect if a JPEG was saved using huffman encoding or not (progressive), try the below code. I only spent a few hours of research but I wanted to share. This could be more optimized, but it works and allows me the ability to detect different JPEG encodings as well.

public bool IsJpegProgressive(string file)
{
    Stream stream = new FileStream(file, FileMode.Open);
    bool flag = false;
    byte[] buffer = new byte[0x10000];
    if ((0xff == stream.ReadByte()) && (0xd8 == stream.ReadByte()))
    {
        while (0xff == stream.ReadByte())
        {
            int num = stream.ReadByte();
            int count = ((stream.ReadByte() << 8) | stream.ReadByte()) - 2;
            stream.Read(buffer, 0, count);
            if (0xc2 == num)
            {
                flag = true;
            }
        }
        stream.Close();
        stream.Dispose();
        stream = null;
        return flag;
    }
    stream.Close();
    stream.Dispose();
    stream = null;
    return false;
}
for more information on the JPEG header go here:
http://www.obrador.com/essentialjpeg/headerinfo.htm