diff options
author | Martin Emde <martin.emde@gmail.com> | 2023-02-16 18:03:41 -0800 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2023-03-07 20:21:43 +0000 |
commit | 85a1738ab37b3348fc0b924804ca4b209f34fbf7 (patch) | |
tree | 92706ff6ce6f4ae5baa1b06095468678de236f5d /lib/rubygems/package/tar_reader.rb | |
parent | 719a7726d17f0800b8f8ef42f3f48e7558d5a444 (diff) |
[rubygems/rubygems] Add TarReader::Entry#seek to seek within the tar file entry
TarReader#each previously implemented a partial version of seek.
This code moved to Entry#seek for use from TarReader#each.
Entry#close now returns nil instead of true, like IO#close.
Closing an Entry now seeks to the end of the Entry, seeking past
any remaining zero byte tar file padding and moving the io to the
correcty position to read the next file in the archive.
Uses seek for Entry#rewind and #pos=, fixing the tar->gzip->tar nested
rewind that would break previous to this change.
Add Entry.open that behaves more like File.open.
https://github.com/rubygems/rubygems/commit/f5149565d5
Diffstat (limited to 'lib/rubygems/package/tar_reader.rb')
-rw-r--r-- | lib/rubygems/package/tar_reader.rb | 28 |
1 files changed, 0 insertions, 28 deletions
diff --git a/lib/rubygems/package/tar_reader.rb b/lib/rubygems/package/tar_reader.rb index cdc3fdc015..9f1d49035b 100644 --- a/lib/rubygems/package/tar_reader.rb +++ b/lib/rubygems/package/tar_reader.rb @@ -53,39 +53,11 @@ class Gem::Package::TarReader def each return enum_for __method__ unless block_given? - use_seek = @io.respond_to?(:seek) - until @io.eof? do header = Gem::Package::TarHeader.from @io return if header.empty? - entry = Gem::Package::TarReader::Entry.new header, @io - size = entry.header.size - yield entry - - skip = (512 - (size % 512)) % 512 - pending = size - entry.bytes_read - - if use_seek - begin - # avoid reading if the @io supports seeking - @io.seek pending, IO::SEEK_CUR - pending = 0 - rescue Errno::EINVAL - end - end - - # if seeking isn't supported or failed - while pending > 0 do - bytes_read = @io.read([pending, 4096].min).size - raise UnexpectedEOF if @io.eof? - pending -= bytes_read - end - - @io.read skip # discard trailing zeros - - # make sure nobody can use #read, #getc or #rewind anymore entry.close end end |