Class | Gem::Format |
In: |
lib/rubygems/format.rb
|
Parent: | Object |
Gem::Format knows the guts of the RubyGem .gem file format and provides the capability to read gem files
file_entries | [RW] | |
gem_path | [RW] | |
spec | [RW] |
Reads the gem file_path using security_policy and returns a Format representing the data in the gem
# File lib/rubygems/format.rb, line 30 30: def self.from_file_by_path(file_path, security_policy = nil) 31: unless File.file?(file_path) 32: raise Gem::Exception, "Cannot load gem at [#{file_path}] in #{Dir.pwd}" 33: end 34: 35: start = File.read file_path, 20 36: 37: if start.nil? or start.length < 20 then 38: nil 39: elsif start.include?("MD5SUM =") # old version gems 40: require 'rubygems/old_format' 41: 42: Gem::OldFormat.from_file_by_path file_path 43: else 44: begin 45: open file_path, Gem.binary_mode do |io| 46: from_io io, file_path, security_policy 47: end 48: rescue Gem::Package::TarInvalidError => e 49: message = "corrupt gem (#{e.class}: #{e.message})" 50: raise Gem::Package::FormatError.new(message, file_path) 51: end 52: end 53: end
Reads a gem from io at gem_path using security_policy and returns a Format representing the data from the gem
# File lib/rubygems/format.rb, line 59 59: def self.from_io(io, gem_path="(io)", security_policy = nil) 60: format = new gem_path 61: 62: Gem::Package.open io, 'r', security_policy do |pkg| 63: format.spec = pkg.metadata 64: format.file_entries = [] 65: 66: pkg.each do |entry| 67: size = entry.header.size 68: mode = entry.header.mode 69: 70: format.file_entries << [{ 71: "size" => size, "mode" => mode, "path" => entry.full_name, 72: }, 73: entry.read 74: ] 75: end 76: end 77: 78: format 79: end