Class: Kafka::GzipCodec

Inherits:
Object
  • Object
show all
Defined in:
lib/kafka/gzip_codec.rb

Instance Method Summary collapse

Instance Method Details

#codec_idObject



5
6
7
# File 'lib/kafka/gzip_codec.rb', line 5

def codec_id
  1
end

#compress(data) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/kafka/gzip_codec.rb', line 17

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

#decompress(data) ⇒ Object



28
29
30
31
32
# File 'lib/kafka/gzip_codec.rb', line 28

def decompress(data)
  buffer = StringIO.new(data)
  reader = Zlib::GzipReader.new(buffer)
  reader.read
end

#loadObject



13
14
15
# File 'lib/kafka/gzip_codec.rb', line 13

def load
  require "zlib"
end

#produce_api_min_versionObject



9
10
11
# File 'lib/kafka/gzip_codec.rb', line 9

def produce_api_min_version
  0
end