Method: Nodectl::Stream::File#initialize

Defined in:
lib/nodectl/stream/file.rb

#initialize(file, options = {}) ⇒ File

Returns a new instance of File.



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/nodectl/stream/file.rb', line 2

def initialize(file, options = {})
  @onread  = []
  @onclose = []

  if file.respond_to? :read_nonblock
    @file = file
  else
    begin
      @file = File.new(file)
    rescue Errno::ENOENT
      raise Nodectl::NotFound, "file not found"
    end
  end

  @options = options

  if @options[:end_offset]
    offset = @file.size - @options[:end_offset]
    if offset > 0
      @file.seek(offset)
      @options[:end_offset].times do
        break if @file.readchar == "\n"
      end
    end
  end
end