Skip to content
Permalink
Browse files
Added ARGF.read_nonblock
Fixes #3594
  • Loading branch information
YorickPeterse committed Jan 29, 2016
1 parent f097b84 commit d99df97d781e6d770db3183df262abed79c422a6
Showing with 24 additions and 1 deletion.
  1. +24 −1 kernel/common/argf.rb
@@ -363,6 +363,29 @@ def read(bytes=nil, output=nil)
output
end

def read_nonblock(maxlen, output = nil, exception: true)
output ||= default_value

unless advance!
output.clear
raise EOFError, "ARGF at end"
end

begin
out = @stream.read_nonblock(maxlen, output, exception: exception)

return out if out == :wait_readable
rescue EOFError => e
raise e if @use_stdin_only

@stream.close
@advance = true
advance! or raise e
end

return output
end

#
# Read next line of text.
#
@@ -530,7 +553,7 @@ def advance!
@advance = false

file = ARGV.shift
@stream = stream(file)
@stream = stream(file)
@filename = file

if $-i && @stream != STDIN

0 comments on commit d99df97

Please sign in to comment.