# File lib/rubygems/format.rb, line 30
  def self.from_file_by_path(file_path, security_policy = nil)
    unless File.exist?(file_path)
      raise Gem::Exception, "Cannot load gem at [#{file_path}] in #{Dir.pwd}"
    end

    start = File.read file_path, 20

    if start.nil? or start.length < 20 then
      nil
    elsif start.include?("MD5SUM =") # old version gems
      require 'rubygems/old_format'

      Gem::OldFormat.from_file_by_path file_path
    else
      begin
        open file_path, Gem.binary_mode do |io|
          from_io io, file_path, security_policy
        end
      rescue Gem::Package::TarInvalidError => e
        message = "corrupt gem (#{e.class}: #{e.message})"
        raise Gem::Package::FormatError.new(message, file_path)
      end
    end
  end