From 3642fe40131220520e961157fa501ee1adf2ebca Mon Sep 17 00:00:00 2001 From: Christopher Aue Date: Tue, 13 Jun 2017 21:40:36 +0200 Subject: fixed #87: IO#read(n) with n > IO::BUF_SIZE --- mrblib/io.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'mrblib') diff --git a/mrblib/io.rb b/mrblib/io.rb index 3ea839379..f538af490 100644 --- a/mrblib/io.rb +++ b/mrblib/io.rb @@ -205,10 +205,12 @@ class IO break end - if length && length <= @buf.size - array.push @buf[0, length] - @buf = @buf[length, @buf.size - length] - break + if length + consume = (length <= @buf.size) ? length : @buf.size + array.push @buf[0, consume] + @buf = @buf[consume, @buf.size - consume] + length -= consume + break if length == 0 else array.push @buf @buf = '' -- cgit v1.2.3