Skip to content

Instantly share code, notes, and snippets.

@rpl
Last active May 6, 2025 13:50
Show Gist options
  • Save rpl/c21b881d0fc9ece430f94ef3c53dd72d to your computer and use it in GitHub Desktop.
Save rpl/c21b881d0fc9ece430f94ef3c53dd72d to your computer and use it in GitHub Desktop.
mozlz4 python utils
#!/usr/bin/env python
import io
import sys
import lz4.block
MAGIC = b'mozLz40\0'
for path in sys.argv[1:]:
dest_path = f'{path}.lz4'
print(f'Compressing {path} to {dest_path}')
with io.open(path,'rb') as fsrc:
data = fsrc.read()
with io.open(f'{path}.lz4', 'wb') as fdst:
fdst.write(MAGIC)
fdst.write(lz4.block.compress(data))
#!/usr/bin/env python
import io
import sys
import lz4.block
MAGIC = b'mozLz40\0'
for path in sys.argv[1:]:
with io.open(path, 'rb') as f:
magic = f.read(len(MAGIC))
if magic != MAGIC:
raise Exception('Bad magic number')
print(lz4.block.decompress(f.read()).decode("utf-8"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment