Skip to content

Commit

Permalink
Force lz4 to disable Kafka-unsupported block linking when encoding (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mnito authored and dpkp committed Apr 19, 2018
1 parent b6ffbaa commit afc6346
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion kafka/codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@

try:
import lz4.frame as lz4

def _lz4_compress(payload, **kwargs):
# Kafka does not support LZ4 dependent blocks
try:
# For lz4>=0.12.0
kwargs.pop('block_linked', None)
return lz4.compress(payload, block_linked=False, **kwargs)
except TypeError:
# For earlier versions of lz4
kwargs.pop('block_mode', None)
return lz4.compress(payload, block_mode=1, **kwargs)

except ImportError:
lz4 = None

Expand Down Expand Up @@ -202,7 +214,7 @@ def snappy_decode(payload):


if lz4:
lz4_encode = lz4.compress # pylint: disable-msg=no-member
lz4_encode = _lz4_compress # pylint: disable-msg=no-member
elif lz4f:
lz4_encode = lz4f.compressFrame # pylint: disable-msg=no-member
elif lz4framed:
Expand Down

0 comments on commit afc6346

Please sign in to comment.