D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
opt
/
td-agent
/
embedded
/
lib
/
ruby
/
gems
/
2.1.0
/
gems
/
ruby-kafka-0.4.2
/
lib
/
kafka
/
Filename :
gzip_codec.rb
back
Copy
module Kafka class GzipCodec def initialize require "zlib" end def codec_id 1 end def compress(data) buffer = StringIO.new buffer.set_encoding(Encoding::BINARY) writer = Zlib::GzipWriter.new(buffer, Zlib::DEFAULT_COMPRESSION, Zlib::DEFAULT_STRATEGY) writer.write(data) writer.close buffer.string end def decompress(data) buffer = StringIO.new(data) reader = Zlib::GzipReader.new(buffer) reader.read end end end