[rubygems/rubygems] Fix TarReader::Entry#read/partial to match File#read and StringIO#read

TarReader is used as an IO object, but doesn't behave the same as other
implementations. These fixes make `read` and `readpartial` conform to the
interface of StringIO and File.

https://github.com/rubygems/rubygems/commit/bba32d7217
This commit is contained in:
Martin Emde 2023-01-31 16:12:28 -08:00 коммит произвёл git
Родитель 0853703ec6
Коммит 65ca14ea6e
1 изменённых файлов: 6 добавлений и 4 удалений

Просмотреть файл

@ -130,9 +130,10 @@ class Gem::Package::TarReader::Entry
def read(len = nil)
check_closed
return nil if @read >= @header.size
len ||= @header.size - @read
return nil if len > 0 && @read >= @header.size
max_read = [len, @header.size - @read].min
ret = @io.read max_read
@ -144,9 +145,10 @@ class Gem::Package::TarReader::Entry
def readpartial(maxlen = nil, outbuf = "".b)
check_closed
raise EOFError if @read >= @header.size
maxlen ||= @header.size - @read
raise EOFError if maxlen > 0 && @read >= @header.size
max_read = [maxlen, @header.size - @read].min
@io.readpartial(max_read, outbuf)