import lz4.block
def mozlz4_to_text(filepath):
bytestream = open(filepath, "rb")
bytestream.read(8) valid_bytes = bytestream.read()
text = lz4.block.decompress(valid_bytes)
return text
def main(args):
filepath_in = args[0]
if len(args) < 2:
filepath_out = filepath_in[:-3]
else:
filepath_out = args[1]
text = mozlz4_to_text(filepath_in)
with open(filepath_out, "wb") as outfile:
outfile.write(text)
print("Wrote decompressed text to {}".format(filepath_out))
if __name__ == "__main__":
import sys
args = sys.argv[1:]
if args and not args[0] in ("--help", "-h"):
main(args)
else:
print("Usage: mozlz4.py <mozlz4 file to read> <location to write>")