class Fluent::Plugin::Buffer::MemoryChunk

def bytesize

def bytesize
  @chunk_bytes + @adding_bytes
end

def commit

def commit
  @size += @adding_size
  @chunk_bytes += @adding_bytes
  @adding_bytes = @adding_size = 0
  @modified_at = Time.now
  true
end

def concat(bulk, bulk_size)

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

def empty?

def empty?
  @chunk.empty?
end

def initialize(metadata, compress: :text)

def initialize(metadata, compress: :text)
  super
  @chunk = ''.force_encoding(Encoding::ASCII_8BIT)
  @chunk_bytes = 0
  @adding_bytes = 0
  @adding_size = 0
end

def open(**kwargs, &block)

def open(**kwargs, &block)
  StringIO.open(@chunk, &block)
end

def purge

def purge
  super
  @chunk = ''.force_encoding("ASCII-8BIT")
  @chunk_bytes = @size = @adding_bytes = @adding_size = 0
  true
end

def read(**kwargs)

def read(**kwargs)
  @chunk
end

def rollback

def rollback
  @chunk.slice!(@chunk_bytes, @adding_bytes)
  @adding_bytes = @adding_size = 0
  true
end

def size

def size
  @size + @adding_size
end

def write_to(io, **kwargs)

def write_to(io, **kwargs)
  # re-implementation to optimize not to create StringIO
  io.write @chunk
end