Object
Gem::Format knows the guts of the RubyGem .gem file format and provides the capability to read gem files
Reads the gem file_path using security_policy and
returns a Format representing the data in the gem
# File rubygems/format.rb, line 34
def self.from_file_by_path(file_path, security_policy = nil)
format = 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
open file_path, Gem.binary_mode do |io|
from_io io, file_path, security_policy
end
end
end
Reads a gem from io at gem_path using
security_policy and returns a Format
representing the data from the gem
# File rubygems/format.rb, line 60
def self.from_io(io, gem_path="(io)", security_policy = nil)
format = new gem_path
Gem::Package.open io, 'r', security_policy do |pkg|
format.spec = pkg.metadata
format.file_entries = []
pkg.each do |entry|
size = entry.header.size
mode = entry.header.mode
format.file_entries << [{
"size" => size, "mode" => mode, "path" => entry.full_name,
},
entry.read
]
end
end
format
end
Constructs a Format representing the gem’s data
which came from gem_path
# File rubygems/format.rb, line 26
def initialize(gem_path)
@gem_path = gem_path
end
Commenting is here to help enhance the documentation. For example, sample code, or clarification of the documentation.
If you are posting code samples in your comments, please wrap them in "<pre><code class="ruby" > ... </code></pre>" markup in order to get syntax highlighting.
If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.
If you wish to post a correction of the docs, please do so, but also file a bug report so that it can be corrected for the next release. Thank you.