Python Forum

Full Version: compression module for lz4?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i would like to know if there is a module for decompressing the lz4 compression found in the Debian/Ubuntu "lz4" command (as opposed to the lzma compression found in the Debian/Ubuntu "lzma" and "xz" commands which is implement in the lzma module). anyone know (without guessing)?
LZ4 is not xz.

xz is using lzma compression.

To get lz4 with Python:
pip install lz4
The module lzma is in the standard library.

Example:
# stdlib
import subprocess
import lzma

# extern
from lz4.frame import open as lz4_open
# apt-get install python-lz4 or pip install lz4

# LZMA !!!!
print("Compressing with lzma")
with open("test.xz", "wb") as fd:
    subprocess.run(["xz"], input=b"Hello World", stdout=fd)

print("Reading with lzma from stdlib")
with lzma.open("test.xz", "rb") as fd:
    print(fd.read())

print()

# LZ4 !!!
print("Compressing with lz4")
with open("test.lz4", "wb") as fd:
    subprocess.run(["lz4"], input=b"Hello World", stdout=fd)

print("Reading lz4 with external lib")
with lz4_open("test.lz4", "rb") as fd:
    print(fd.read(1024))  # without size I get a memory error