comprime/compress.py
2025-06-17 15:30:36 +02:00

30 lines
761 B
Python
Executable file

#!/usr/bin/env -S python3
import subprocess
import sys
def main():
[_, input] = sys.argv
input_tar = input + ".tar"
output = input + ".cprmt"
print("Compressing '" + input + "' into '" + output + "'.")
subprocess.Popen(["tar", "cf", input_tar, input]).wait()
input_tar_fd = open(input_tar, "rb")
output_fd = open(output, "wb")
byte_index = 0
while True:
read = input_tar_fd.read(1024)
if len(read) == 0:
break
for byte in read:
if byte_index == 0:
output_fd.write(bytes([5, byte]))
else:
output_fd.write(bytes([byte]))
byte_index += 1
byte_index %= 4
print("Done.")
if __name__ == "__main__": main()