class Fluent::Plugin::Buffer::MemoryChunk

Public Class Methods

new(metadata, compress: :text) click to toggle source
Calls superclass method Fluent::Plugin::Buffer::Chunk.new
# File lib/fluent/plugin/buffer/memory_chunk.rb, line 23
def initialize(metadata, compress: :text)
  super
  @chunk = ''.force_encoding(Encoding::ASCII_8BIT)
  @chunk_bytes = 0
  @adding_bytes = 0
  @adding_size = 0
end

Public Instance Methods

bytesize() click to toggle source
# File lib/fluent/plugin/buffer/memory_chunk.rb, line 56
def bytesize
  @chunk_bytes + @adding_bytes
end
commit() click to toggle source
# File lib/fluent/plugin/buffer/memory_chunk.rb, line 41
def commit
  @size += @adding_size
  @chunk_bytes += @adding_bytes

  @adding_bytes = @adding_size = 0
  @modified_at = Time.now
  true
end
concat(bulk, bulk_size) click to toggle source
# File lib/fluent/plugin/buffer/memory_chunk.rb, line 31
def concat(bulk, bulk_size)
  raise "BUG: concatenating to unwritable chunk, now '#{self.state}'" unless self.writable?

  bulk.force_encoding(Encoding::ASCII_8BIT)
  @chunk << bulk
  @adding_bytes += bulk.bytesize
  @adding_size += bulk_size
  true
end
empty?() click to toggle source
# File lib/fluent/plugin/buffer/memory_chunk.rb, line 64
def empty?
  @chunk.empty?
end
open(**kwargs, &block) click to toggle source
# File lib/fluent/plugin/buffer/memory_chunk.rb, line 79
def open(**kwargs, &block)
  StringIO.open(@chunk, &block)
end
purge() click to toggle source
Calls superclass method Fluent::Plugin::Buffer::Chunk#purge
# File lib/fluent/plugin/buffer/memory_chunk.rb, line 68
def purge
  super
  @chunk = ''.force_encoding("ASCII-8BIT")
  @chunk_bytes = @size = @adding_bytes = @adding_size = 0
  true
end
read(**kwargs) click to toggle source
# File lib/fluent/plugin/buffer/memory_chunk.rb, line 75
def read(**kwargs)
  @chunk
end
rollback() click to toggle source
# File lib/fluent/plugin/buffer/memory_chunk.rb, line 50
def rollback
  @chunk.slice!(@chunk_bytes, @adding_bytes)
  @adding_bytes = @adding_size = 0
  true
end
size() click to toggle source
# File lib/fluent/plugin/buffer/memory_chunk.rb, line 60
def size
  @size + @adding_size
end
write_to(io, **kwargs) click to toggle source
# File lib/fluent/plugin/buffer/memory_chunk.rb, line 83
def write_to(io, **kwargs)
  # re-implementation to optimize not to create StringIO
  io.write @chunk
end