Skip to content

Commit

Permalink
Added ARGF.read_nonblock
Browse files Browse the repository at this point in the history
Fixes #3594
  • Loading branch information
Yorick Peterse committed Jan 29, 2016
1 parent f097b84 commit d99df97
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion kernel/common/argf.rb
Expand Up @@ -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.
#
Expand Down Expand Up @@ -530,7 +553,7 @@ def advance!
@advance = false

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

if $-i && @stream != STDIN
Expand Down

0 comments on commit d99df97

Please sign in to comment.