Parent

Methods

Files

Bcat::Reader

ARGF style multi-file streaming interface. Input is read with IO#readpartial to avoid buffering.

Attributes

fds[R]
files[R]

Public Class Methods

new(files=[]) click to toggle source
# 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

Public Instance Methods

each() click to toggle source
# 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
sniff() click to toggle source
# 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.