aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rubygems/package/tar_reader.rb
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-29 06:52:18 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-29 06:52:18 +0000
commit9694bb8cac12969300692dac5a1cf7aa4e3a46cd (patch)
treec3cb423d701f7049ba9382de052e2a937cd1302d /lib/rubygems/package/tar_reader.rb
parent3f606b7063fc7a8b191556365ad343a314719a8d (diff)
downloadruby-9694bb8cac12969300692dac5a1cf7aa4e3a46cd.tar.gz
* lib/rubygems*: Updated to RubyGems 2.0
* test/rubygems*: ditto. * common.mk (prelude): Updated for RubyGems 2.0 source rearrangement. * tool/change_maker.rb: Allow invalid UTF-8 characters in source files. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37976 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems/package/tar_reader.rb')
-rw-r--r--lib/rubygems/package/tar_reader.rb23
1 files changed, 20 insertions, 3 deletions
diff --git a/lib/rubygems/package/tar_reader.rb b/lib/rubygems/package/tar_reader.rb
index e6a71d386c..e257fdd846 100644
--- a/lib/rubygems/package/tar_reader.rb
+++ b/lib/rubygems/package/tar_reader.rb
@@ -9,7 +9,7 @@
class Gem::Package::TarReader
- include Gem::Package
+ include Enumerable
##
# Raised if the tar IO is not seekable
@@ -52,9 +52,9 @@ class Gem::Package::TarReader
# Iterates over files in the tarball yielding each entry
def each
- loop do
- return if @io.eof?
+ return enum_for __method__ unless block_given?
+ until @io.eof? do
header = Gem::Package::TarHeader.from @io
return if header.empty?
@@ -100,6 +100,23 @@ class Gem::Package::TarReader
end
end
+ ##
+ # Seeks through the tar file until it finds the +entry+ with +name+ and
+ # yields it. Rewinds the tar file to the beginning when the block
+ # terminates.
+
+ def seek name # :yields: entry
+ found = find do |entry|
+ entry.full_name == name
+ end
+
+ return unless found
+
+ return yield found
+ ensure
+ rewind
+ end
+
end
require 'rubygems/package/tar_reader/entry'