def decode(length, type)
      # Check if values are valid:
      if (@index + length) > @string.length
        # The index number is bigger then the length of the binary string.
        # We have reached the end and will return nil.
        value = nil
      else
        if type == "AT"
          value = decode_tag
        else
          # Decode the binary string and return value:
          value = @string.slice(@index, length).unpack(vr_to_str(type))
          # If the result is an array of one element, return the element instead of the array.
          # If result is contained in a multi-element array, the original array is returned.
          if value.length == 1
            value = value[0]
            # If value is a string, strip away possible trailing whitespace:
            # Do this using gsub instead of ruby-core #strip to keep trailing carriage
            # returns, etc., because that is valid whitespace that we want to have included
            # (i.e. in extended header data, AFNI writes a \n at the end of it's xml info, 
            # and that must be kept in order to not change the file on writing back out).
            value.gsub!(/\000*$/, "") if value.respond_to? :gsub!
          end
          # Update our position in the string:
          skip(length)
        end
      end
      return value
    end
def decode(length, type)
      # Check if values are valid:
      if (@index + length) > @string.length
        # The index number is bigger then the length of the binary string.
        # We have reached the end and will return nil.
        value = nil
      else
        if type == "AT"
          value = decode_tag
        else
          # Decode the binary string and return value:
          value = @string.slice(@index, length).unpack(vr_to_str(type))
          # If the result is an array of one element, return the element instead of the array.
          # If result is contained in a multi-element array, the original array is returned.
          if value.length == 1
            value = value[0]
            # If value is a string, strip away possible trailing whitespace:
            # Do this using gsub instead of ruby-core #strip to keep trailing carriage
            # returns, etc., because that is valid whitespace that we want to have included
            # (i.e. in extended header data, AFNI writes a \n at the end of it's xml info, 
            # and that must be kept in order to not change the file on writing back out).
            value.gsub!(/\000*$/, "") if value.respond_to? :gsub!
          end
          # Update our position in the string:
          skip(length)
        end
      end
      return value
    end
Creates a Stream instance.

 === Parameters

 * <tt>binary</tt> -- A binary string.
 * <tt>string_endian</tt> -- Boolean. The endianness of the instance string (true for big endian, false for small endian).
 * <tt>options</tt> -- A hash of parameters.

 === Options

 * <tt>:index</tt> -- Fixnum. A position (offset) in the instance string where reading will start.

 Decodes a section of the instance string and returns the formatted data.
 The instance index is offset in accordance with the length read.

 === Notes

 * If multiple numbers are decoded, these are returned in an array.

 === Parameters

 * <tt>length</tt> -- Fixnum. The string length which will be decoded.
 * <tt>type</tt> -- String. The type (vr) of data to decode.