aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rubygems/format.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rubygems/format.rb')
-rw-r--r--lib/rubygems/format.rb26
1 files changed, 16 insertions, 10 deletions
diff --git a/lib/rubygems/format.rb b/lib/rubygems/format.rb
index 378a93018c..7dc127d5f4 100644
--- a/lib/rubygems/format.rb
+++ b/lib/rubygems/format.rb
@@ -43,15 +43,12 @@ module Gem
# check for old version gem
if File.read(file_path, 20).include?("MD5SUM =")
- #alert_warning "Gem #{file_path} is in old format."
require 'rubygems/old_format'
+
format = OldFormat.from_file_by_path(file_path)
else
- begin
- f = File.open(file_path, 'rb')
- format = from_io(f, file_path, security_policy)
- ensure
- f.close unless f.closed?
+ open file_path, Gem.binary_mode do |io|
+ format = from_io io, file_path, security_policy
end
end
@@ -65,15 +62,24 @@ module Gem
# io:: [IO] Stream from which to read the gem
#
def self.from_io(io, gem_path="(io)", security_policy = nil)
- format = self.new(gem_path)
- Package.open_from_io(io, 'r', security_policy) do |pkg|
+ format = new gem_path
+
+ Package.open io, 'r', security_policy do |pkg|
format.spec = pkg.metadata
format.file_entries = []
+
pkg.each do |entry|
- format.file_entries << [{"size" => entry.size, "mode" => entry.mode,
- "path" => entry.full_name}, entry.read]
+ 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