Skip to content

Instantly share code, notes, and snippets.

@slowpeek
Last active July 21, 2024 20:22
Show Gist options
  • Save slowpeek/06bfe5f00900f09ad015ddf6da1d0714 to your computer and use it in GitHub Desktop.
Save slowpeek/06bfe5f00900f09ad015ddf6da1d0714 to your computer and use it in GitHub Desktop.
Minimal tool to compress/decompress mozlz4 format
#!/usr/bin/env python3
# MIT license (c) 2024 https://github.com/slowpeek
# Homepage: https://gist.github.com/slowpeek/06bfe5f00900f09ad015ddf6da1d0714
# Minimal tool to compress/decompress mozlz4 format
import sys
import lz4.block
def bye( s, exit_code=1):
print(s)
sys.exit(exit_code)
def main():
usage = "Usage: mozlz4 [-d] <in >out"
argc = len(sys.argv)
if (argc > 2):
bye(usage)
fi = sys.stdin.buffer
fo = sys.stdout.buffer
magic = b"mozLz40\0"
if (argc == 1):
fo.write(magic)
fo.write(lz4.block.compress(fi.read()))
elif (sys.argv[1] == "-d"):
if fi.read(8) != magic:
bye("input does not look like mozlz4")
fo.write(lz4.block.decompress(fi.read()))
else:
bye(usage)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment