diff options
Diffstat (limited to 'lib/rubygems/package')
-rw-r--r-- | lib/rubygems/package/file_source.rb | 33 | ||||
-rw-r--r-- | lib/rubygems/package/io_source.rb | 45 | ||||
-rw-r--r-- | lib/rubygems/package/old.rb | 8 | ||||
-rw-r--r-- | lib/rubygems/package/source.rb | 3 | ||||
-rw-r--r-- | lib/rubygems/package/tar_reader/entry.rb | 2 |
5 files changed, 87 insertions, 4 deletions
diff --git a/lib/rubygems/package/file_source.rb b/lib/rubygems/package/file_source.rb new file mode 100644 index 0000000000..85316f62e7 --- /dev/null +++ b/lib/rubygems/package/file_source.rb @@ -0,0 +1,33 @@ +## +# The primary source of gems is a file on disk, including all usages +# internal to rubygems. +# +# This is a private class, do not depend on it directly. Instead, pass a path +# object to `Gem::Package.new`. + +class Gem::Package::FileSource < Gem::Package::Source # :nodoc: all + + attr_reader :path + + def initialize path + @path = path + end + + def start + @start ||= File.read path, 20 + end + + def present? + File.exist? path + end + + def with_write_io &block + open path, 'wb', &block + end + + def with_read_io &block + open path, 'rb', &block + end + +end + diff --git a/lib/rubygems/package/io_source.rb b/lib/rubygems/package/io_source.rb new file mode 100644 index 0000000000..f89593dd2d --- /dev/null +++ b/lib/rubygems/package/io_source.rb @@ -0,0 +1,45 @@ +## +# Supports reading and writing gems from/to a generic IO object. This is +# useful for other applications built on top of rubygems, such as +# rubygems.org. +# +# This is a private class, do not depend on it directly. Instead, pass an IO +# object to `Gem::Package.new`. + +class Gem::Package::IOSource < Gem::Package::Source # :nodoc: all + + attr_reader :io + + def initialize io + @io = io + end + + def start + @start ||= begin + if io.pos > 0 + raise Gem::Package::Error, "Cannot read start unless IO is at start" + end + + value = io.read 20 + io.rewind + value + end + end + + def present? + true + end + + def with_read_io + yield io + end + + def with_write_io + yield io + end + + def path + end + +end + diff --git a/lib/rubygems/package/old.rb b/lib/rubygems/package/old.rb index 31c4111d33..65bcbb2283 100644 --- a/lib/rubygems/package/old.rb +++ b/lib/rubygems/package/old.rb @@ -37,7 +37,7 @@ class Gem::Package::Old < Gem::Package return @contents if @contents - open @gem, 'rb' do |io| + @gem.with_read_io do |io| read_until_dashes io # spec header = file_list io @@ -53,7 +53,7 @@ class Gem::Package::Old < Gem::Package errstr = "Error reading files from gem" - open @gem, 'rb' do |io| + @gem.with_read_io do |io| read_until_dashes io # spec header = file_list io raise Gem::Exception, errstr unless header @@ -83,7 +83,7 @@ class Gem::Package::Old < Gem::Package out.write file_data end - say destination if Gem.configuration.really_verbose + verbose destination end end rescue Zlib::DataError @@ -136,7 +136,7 @@ class Gem::Package::Old < Gem::Package yaml = '' - open @gem, 'rb' do |io| + @gem.with_read_io do |io| skip_ruby io read_until_dashes io do |line| yaml << line diff --git a/lib/rubygems/package/source.rb b/lib/rubygems/package/source.rb new file mode 100644 index 0000000000..1f18d479da --- /dev/null +++ b/lib/rubygems/package/source.rb @@ -0,0 +1,3 @@ +class Gem::Package::Source # :nodoc: +end + diff --git a/lib/rubygems/package/tar_reader/entry.rb b/lib/rubygems/package/tar_reader/entry.rb index 7034e59210..737c7639c6 100644 --- a/lib/rubygems/package/tar_reader/entry.rb +++ b/lib/rubygems/package/tar_reader/entry.rb @@ -129,6 +129,8 @@ class Gem::Package::TarReader::Entry ret end + alias readpartial read # :nodoc: + ## # Rewinds to the beginning of the tar file entry |