Class | Bcat::Reader |
In: |
lib/bcat/reader.rb
|
Parent: | Object |
ARGF style multi-file streaming interface. Input is read with IO#readpartial to avoid buffering.
args | [R] | |
fds | [R] | |
is_command | [R] |
# File lib/bcat/reader.rb, line 11 11: def initialize(is_command, args=[]) 12: @is_command = is_command 13: @args = args 14: end
# File lib/bcat/reader.rb, line 35 35: def each 36: yield @buf.shift while @buf.any? 37: while fd = fds.first 38: fds.shift and next if fd.closed? 39: fd.sync = true 40: begin 41: while buf = fd.readpartial(4096) 42: yield buf 43: end 44: rescue EOFError 45: fd.close 46: end 47: fds.shift 48: end 49: end
# File lib/bcat/reader.rb, line 16 16: def open 17: @fds = is_command ? open_command : open_files 18: @buf = [] 19: end
# File lib/bcat/reader.rb, line 21 21: def open_command 22: [IO.popen(args.join(' '), 'rb')] 23: end
# File lib/bcat/reader.rb, line 25 25: def open_files 26: args.map do |f| 27: if f == '-' 28: $stdin 29: else 30: File.open(f, 'rb') 31: end 32: end 33: end