def check_header
      begin
        starting_index = @stream.index

        # Check sizeof_hdr
        @stream.index = 0;
        sizeof_hdr = @stream.decode(4, "UL")
        raise IOError, "Bad Header Length #{sizeof_hdr}" unless sizeof_hdr == 348

        # Check magic
        @stream.index = 344;
        magic = @stream.decode(4, "STR")
        raise IOError, "Bad Magic Code #{magic} (should be ni1 or n+1)" unless MAGIC.include?(magic)

      rescue IOError => e
        raise IOError, "Header appears to be malformed: #{e}"
      else
        @stream.index = starting_index
      end
    end
def check_header
      begin
        starting_index = @stream.index

        # Check sizeof_hdr
        @stream.index = 0;
        sizeof_hdr = @stream.decode(4, "UL")
        raise IOError, "Bad Header Length #{sizeof_hdr}" unless sizeof_hdr == 348

        # Check magic
        @stream.index = 344;
        magic = @stream.decode(4, "STR")
        raise IOError, "Bad Magic Code #{magic} (should be ni1 or n+1)" unless MAGIC.include?(magic)

      rescue IOError => e
        raise IOError, "Header appears to be malformed: #{e}"
      else
        @stream.index = starting_index
      end
    end
NIFTI uses the header length (first 4 bytes) to be 348 number of "ni1\0"
 or "n+1\0" as the last 4 bytes to be magic numbers to validate the header.

 The header is usually checked before any data is read, but can be
 checked at any point in the process as the stream index is reset to its
 original position after validation.

 There are no options - the method will raise an IOError if any of the
 magic numbers are not valid.