Object
ARGF style multi-file streaming interface. Input is read with IO#readpartial to avoid buffering.
# File lib/bcat/reader.rb, line 10 def initialize(files=[]) @files = files @fds = files.map do |f| if f == '-' $stdin else File.open(f, 'rb') end end @buf = [] end
# File lib/bcat/reader.rb, line 23 def each yield @buf.shift while @buf.any? while fd = fds.first fd.sync = true begin while buf = fd.readpartial(4096) yield buf end rescue EOFError fd.close end fds.shift end end
# File lib/bcat/reader.rb, line 38 def sniff @format ||= catch :detect do each do |chunk| @buf << chunk case chunk when /\A\s*</ throw :detect, 'html' when /\A\s*[^<]/ throw :detect, 'text' end end throw :detect, 'text' end end
[Validate]
Generated with the Darkfish Rdoc Generator 2.