summaryrefslogtreecommitdiffhomepage
path: root/mrblib
diff options
context:
space:
mode:
Diffstat (limited to 'mrblib')
-rw-r--r--mrblib/io.rb10
1 files changed, 6 insertions, 4 deletions
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 = ''