summaryrefslogtreecommitdiff
path: root/lib/rubygems/package/tar_reader.rb
diff options
context:
space:
mode:
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'