class Fluent::FileBufferChunk

Attributes

path[R]
unique_id[R]

Public Class Methods

new(key, path, unique_id, mode="a+", symlink_path = nil) click to toggle source
Calls superclass method Fluent::BufferChunk.new
# File lib/fluent/plugin/buf_file.rb, line 19
def initialize(key, path, unique_id, mode="a+", symlink_path = nil)
  super(key)
  @path = path
  @unique_id = unique_id
  @file = File.open(@path, mode, DEFAULT_FILE_PERMISSION)
  @file.sync = true
  @size = @file.stat.size
  FileUtils.ln_sf(@path, symlink_path) if symlink_path
end

Public Instance Methods

<<(data) click to toggle source
# File lib/fluent/plugin/buf_file.rb, line 31
def <<(data)
  @file.write(data)
  @size += data.bytesize
end
close() click to toggle source
# File lib/fluent/plugin/buf_file.rb, line 44
def close
  stat = @file.stat
  @file.close
  if stat.size == 0
    File.unlink(@path)
  end
end
empty?() click to toggle source
# File lib/fluent/plugin/buf_file.rb, line 40
def empty?
  @size == 0
end
mv(path) click to toggle source
# File lib/fluent/plugin/buf_file.rb, line 67
def mv(path)
  File.rename(@path, path)
  @path = path
end
open() { |file| ... } click to toggle source
# File lib/fluent/plugin/buf_file.rb, line 62
def open(&block)
  @file.pos = 0
  yield @file
end
purge() click to toggle source
# File lib/fluent/plugin/buf_file.rb, line 52
def purge
  @file.close
  File.unlink(@path) rescue nil  # TODO rescue?
end
read() click to toggle source
# File lib/fluent/plugin/buf_file.rb, line 57
def read
  @file.pos = 0
  @file.read
end
size() click to toggle source
# File lib/fluent/plugin/buf_file.rb, line 36
def size
  @size
end