| 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 34
34: def self.from_file_by_path(file_path, security_policy = nil)
35: format = nil
36:
37: unless File.exist?(file_path)
38: raise Gem::Exception, "Cannot load gem at [#{file_path}] in #{Dir.pwd}"
39: end
40:
41: start = File.read file_path, 20
42:
43: if start.nil? or start.length < 20 then
44: nil
45: elsif start.include?("MD5SUM =") # old version gems
46: require 'rubygems/old_format'
47:
48: Gem::OldFormat.from_file_by_path file_path
49: else
50: open file_path, Gem.binary_mode do |io|
51: from_io io, file_path, security_policy
52: end
53: end
54: 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 60
60: def self.from_io(io, gem_path="(io)", security_policy = nil)
61: format = new gem_path
62:
63: Gem::Package.open io, 'r', security_policy do |pkg|
64: format.spec = pkg.metadata
65: format.file_entries = []
66:
67: pkg.each do |entry|
68: size = entry.header.size
69: mode = entry.header.mode
70:
71: format.file_entries << [{
72: "size" => size, "mode" => mode, "path" => entry.full_name,
73: },
74: entry.read
75: ]
76: end
77: end
78:
79: format
80: end