File tree 4 files changed +19
-15
lines changed
4 files changed +19
-15
lines changed Original file line number Diff line number Diff line change @@ -21,9 +21,13 @@ def self.codecs
21
21
end
22
22
23
23
def self . find_codec ( name )
24
- CODECS . fetch ( name ) do
24
+ codec = CODECS . fetch ( name ) do
25
25
raise "Unknown compression codec #{ name } "
26
26
end
27
+
28
+ codec . load
29
+
30
+ codec
27
31
end
28
32
29
33
def self . find_codec_by_id ( codec_id )
Original file line number Diff line number Diff line change 1
1
module Kafka
2
2
class GzipCodec
3
- def initialize
4
- require "zlib"
5
- end
6
-
7
3
def codec_id
8
4
1
9
5
end
10
6
7
+ def load
8
+ require "zlib"
9
+ end
10
+
11
11
def compress ( data )
12
12
buffer = StringIO . new
13
13
buffer . set_encoding ( Encoding ::BINARY )
Original file line number Diff line number Diff line change 1
1
module Kafka
2
2
class LZ4Codec
3
- def initialize
3
+ def codec_id
4
+ 3
5
+ end
6
+
7
+ def load
4
8
require "extlz4"
5
9
rescue LoadError
6
10
raise LoadError , "using lz4 compression requires adding a dependency on the `extlz4` gem to your Gemfile."
7
11
end
8
12
9
- def codec_id
10
- 3
11
- end
12
-
13
13
def compress ( data )
14
14
LZ4 . encode ( data )
15
15
end
Original file line number Diff line number Diff line change 1
1
module Kafka
2
2
class SnappyCodec
3
- def initialize
3
+ def codec_id
4
+ 2
5
+ end
6
+
7
+ def load
4
8
require "snappy"
5
9
rescue LoadError
6
10
raise LoadError ,
7
11
"Using snappy compression requires adding a dependency on the `snappy` gem to your Gemfile."
8
12
end
9
13
10
- def codec_id
11
- 2
12
- end
13
-
14
14
def compress ( data )
15
15
Snappy . deflate ( data )
16
16
end
You can’t perform that action at this time.
0 commit comments