File tree Expand file tree Collapse file tree 4 files changed +19
-15
lines changed Expand file tree Collapse file tree 4 files changed +19
-15
lines changed Original file line number Diff line number Diff line change @@ -21,9 +21,13 @@ def self.codecs
2121 end
2222
2323 def self . find_codec ( name )
24- CODECS . fetch ( name ) do
24+ codec = CODECS . fetch ( name ) do
2525 raise "Unknown compression codec #{ name } "
2626 end
27+
28+ codec . load
29+
30+ codec
2731 end
2832
2933 def self . find_codec_by_id ( codec_id )
Original file line number Diff line number Diff line change 11module Kafka
22 class GzipCodec
3- def initialize
4- require "zlib"
5- end
6-
73 def codec_id
84 1
95 end
106
7+ def load
8+ require "zlib"
9+ end
10+
1111 def compress ( data )
1212 buffer = StringIO . new
1313 buffer . set_encoding ( Encoding ::BINARY )
Original file line number Diff line number Diff line change 11module Kafka
22 class LZ4Codec
3- def initialize
3+ def codec_id
4+ 3
5+ end
6+
7+ def load
48 require "extlz4"
59 rescue LoadError
610 raise LoadError , "using lz4 compression requires adding a dependency on the `extlz4` gem to your Gemfile."
711 end
812
9- def codec_id
10- 3
11- end
12-
1313 def compress ( data )
1414 LZ4 . encode ( data )
1515 end
Original file line number Diff line number Diff line change 11module Kafka
22 class SnappyCodec
3- def initialize
3+ def codec_id
4+ 2
5+ end
6+
7+ def load
48 require "snappy"
59 rescue LoadError
610 raise LoadError ,
711 "Using snappy compression requires adding a dependency on the `snappy` gem to your Gemfile."
812 end
913
10- def codec_id
11- 2
12- end
13-
1414 def compress ( data )
1515 Snappy . deflate ( data )
1616 end
You can’t perform that action at this time.
0 commit comments