# File lib/rpm/package.rb, line 223
    def [](tag)
      val = nil
      tagc = ::FFI::AutoPointer.new(RPM::C.rpmtdNew, Package.method(:release_td))

      return nil if (RPM::C.headerGet(ptr, tag, tagc, 
                      RPM::C::HEADERGET_MINMEM) == 0)

      type = RPM::C.rpmtdType(tagc)
      count = RPM::C.rpmtdCount(tagc)
      ret_type = RPM::C.rpmTagGetReturnType(tag)

      method_name = case type
        when :int8_type, :char_type, :int16_type, :int32_type, :int64_type then :rpmtdGetNumber
        when :string_type, :string_array_type, :bin_type then :rpmtdGetString
        else raise NotImplementedError, "Don't know how to retrieve type '#{type}'"
      end

      is_array = case
        when count > 1 then true
        when ret_type == :array_return_type then true
        when type == :string_array_type then true
        else false
      end

      if is_array
        ret = []
        RPM::C.rpmtdInit(tagc)
        while RPM::C.rpmtdNext(tagc) != -1
          ret << RPM::C.send(method_name, tagc)
        end
        return ret
      end
      
      return RPM::C.send(method_name, tagc)
    end