diff options
author | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-06-09 21:38:59 +0000 |
---|---|---|
committer | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-06-09 21:38:59 +0000 |
commit | 31c94ffeb5f09d09ac2c86fc9e6614e38251a43d (patch) | |
tree | 10e44506238c7af3d7c9d822111996731726e38d /lib/rubygems/format.rb | |
parent | a6afbaeb3be396c0fdea3b9077d9256c59edcfca (diff) | |
download | ruby-31c94ffeb5f09d09ac2c86fc9e6614e38251a43d.tar.gz |
Update to RubyGems 1.3.4 r2223
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems/format.rb')
-rw-r--r-- | lib/rubygems/format.rb | 124 |
1 files changed, 62 insertions, 62 deletions
diff --git a/lib/rubygems/format.rb b/lib/rubygems/format.rb index 49a3951e26..b2e7897339 100644 --- a/lib/rubygems/format.rb +++ b/lib/rubygems/format.rb @@ -8,80 +8,80 @@ require 'fileutils' require 'rubygems/package' -module Gem +## +# Gem::Format knows the guts of the RubyGem .gem file format and provides the +# capability to read gem files + +class Gem::Format + + attr_accessor :spec, :file_entries, :gem_path + + extend Gem::UserInteraction ## - # The format class knows the guts of the RubyGem .gem file format - # and provides the capability to read gem files + # Constructs an instance of a Format object, representing the gem's + # data structure. # - class Format - attr_accessor :spec, :file_entries, :gem_path - extend Gem::UserInteraction - - ## - # Constructs an instance of a Format object, representing the gem's - # data structure. - # - # gem:: [String] The file name of the gem - # - def initialize(gem_path) - @gem_path = gem_path + # gem:: [String] The file name of the gem + # + def initialize(gem_path) + @gem_path = gem_path + end + + ## + # Reads the named gem file and returns a Format object, representing + # the data from the gem file + # + # file_path:: [String] Path to the gem file + + 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 - ## - # Reads the named gem file and returns a Format object, representing - # the data from the gem file - # - # file_path:: [String] Path to the gem file - # - 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}" + # check for old version gem + if File.read(file_path, 20).include?("MD5SUM =") + require 'rubygems/old_format' + + format = Gem::OldFormat.from_file_by_path(file_path) + else + open file_path, Gem.binary_mode do |io| + format = from_io io, file_path, security_policy end + end - # check for old version gem - if File.read(file_path, 20).include?("MD5SUM =") - require 'rubygems/old_format' + return format + end - format = OldFormat.from_file_by_path(file_path) - else - open file_path, Gem.binary_mode do |io| - format = from_io io, file_path, security_policy - end - end + ## + # Reads a gem from an io stream and returns a Format object, representing + # the data from the gem file + # + # io:: [IO] Stream from which to read the gem - return format - end + def self.from_io(io, gem_path="(io)", security_policy = nil) + format = new gem_path - ## - # Reads a gem from an io stream and returns a Format object, representing - # the data from the gem file - # - # io:: [IO] Stream from which to read the gem - # - def self.from_io(io, gem_path="(io)", security_policy = nil) - format = new gem_path - - 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 + 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 + format.file_entries << [{ + "size" => size, "mode" => mode, "path" => entry.full_name, + }, + entry.read + ] + end end + format end + end + |