mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 16:44:01 +02:00
[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.
bba32d7217
This commit is contained in:
parent
0853703ec6
commit
65ca14ea6e
1 changed files with 6 additions and 4 deletions
|
@ -130,9 +130,10 @@ class Gem::Package::TarReader::Entry
|
||||||
def read(len = nil)
|
def read(len = nil)
|
||||||
check_closed
|
check_closed
|
||||||
|
|
||||||
return nil if @read >= @header.size
|
|
||||||
|
|
||||||
len ||= @header.size - @read
|
len ||= @header.size - @read
|
||||||
|
|
||||||
|
return nil if len > 0 && @read >= @header.size
|
||||||
|
|
||||||
max_read = [len, @header.size - @read].min
|
max_read = [len, @header.size - @read].min
|
||||||
|
|
||||||
ret = @io.read max_read
|
ret = @io.read max_read
|
||||||
|
@ -144,9 +145,10 @@ class Gem::Package::TarReader::Entry
|
||||||
def readpartial(maxlen = nil, outbuf = "".b)
|
def readpartial(maxlen = nil, outbuf = "".b)
|
||||||
check_closed
|
check_closed
|
||||||
|
|
||||||
raise EOFError if @read >= @header.size
|
|
||||||
|
|
||||||
maxlen ||= @header.size - @read
|
maxlen ||= @header.size - @read
|
||||||
|
|
||||||
|
raise EOFError if maxlen > 0 && @read >= @header.size
|
||||||
|
|
||||||
max_read = [maxlen, @header.size - @read].min
|
max_read = [maxlen, @header.size - @read].min
|
||||||
|
|
||||||
@io.readpartial(max_read, outbuf)
|
@io.readpartial(max_read, outbuf)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue