Merge pull request #777 from vetal4444/master

Fix DeprecationWarning when using lz4
This commit is contained in:
Jim Witschey 2017-06-19 11:11:46 -04:00 committed by GitHub
commit cf3ce83f48
1 changed files with 8 additions and 2 deletions

View File

@ -61,6 +61,12 @@ try:
except ImportError:
pass
else:
# The compress and decompress functions we need were moved from the lz4 to
# the lz4.block namespace, so we try both here.
try:
lz4_block = lz4.block
except AttributeError:
lz4_block = lz4
# Cassandra writes the uncompressed message length in big endian order,
# but the lz4 lib requires little endian order, so we wrap these
@ -68,11 +74,11 @@ else:
def lz4_compress(byts):
# write length in big-endian instead of little-endian
return int32_pack(len(byts)) + lz4.compress(byts)[4:]
return int32_pack(len(byts)) + lz4_block.compress(byts)[4:]
def lz4_decompress(byts):
# flip from big-endian to little-endian
return lz4.decompress(byts[3::-1] + byts[4:])
return lz4_block.decompress(byts[3::-1] + byts[4:])
locally_supported_compressions['lz4'] = (lz4_compress, lz4_decompress)