Skip to content

Commit

Permalink
Update write_to
Browse files Browse the repository at this point in the history
* use **kwargs
* not to call super
  • Loading branch information
ganmacs committed Aug 29, 2016
1 parent d97ecdd commit 66f8c18
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
16 changes: 3 additions & 13 deletions lib/fluent/plugin/buffer/chunk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def open(&block)
raise NotImplementedError, "Implement this method in child class"
end

def write_to(io, options = {})
def write_to(io, **kwargs)
open do |i|
IO.copy_stream(i, io)
end
Expand All @@ -161,17 +161,6 @@ def write_to(io, options = {})
module Decompressable
include Fluent::Plugin::Compressable

def write_to(io, options = {})
unless options[:compress] == :gzip
c = decompress(read)
if @chunk.is_a?(String)
@chunk = c
else
# reset io(@chunk) to overwrite new chunk
@chunk.seek(0, IO::SEEK_SET)
@chunk.truncate(0)
@chunk.write c
end
def read(**kwargs)
return super if kwargs[:compress] == :gzip

Expand All @@ -185,7 +174,8 @@ def read(**kwargs)
end
end

super
def write_to(io, **kwargs)
io.write(read(kwargs))
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fluent/plugin/buffer/memory_chunk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def open(&block)
StringIO.open(@chunk, &block)
end

def write_to(io, options = {})
def write_to(io, **kwargs)
# re-implementation to optimize not to create StringIO
io.write @chunk
end
Expand Down

0 comments on commit 66f8c18

Please sign in to comment.