Init.
This commit is contained in:
commit
a70defc85f
7 changed files with 83 additions and 0 deletions
3
README.md
Normal file
3
README.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Comprimé
|
||||
|
||||
Utility for compressing directories into unexecutable files.
|
30
compress.py
Executable file
30
compress.py
Executable file
|
@ -0,0 +1,30 @@
|
|||
#!/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()
|
30
decompr.py
Executable file
30
decompr.py
Executable file
|
@ -0,0 +1,30 @@
|
|||
#!/usr/bin/env -S python3
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
[_, input] = sys.argv
|
||||
input_tar = input.replace(".cprmt", ".tar")
|
||||
output = input_tar.replace(".tar", "")
|
||||
print("Decompressing '" + input + "' into '" + output + "'.")
|
||||
input_fd = open(input, "rb")
|
||||
output_tar_fd = open(input_tar, "wb")
|
||||
byte_index = 0
|
||||
while True:
|
||||
read = input_fd.read(1024)
|
||||
if len(read) == 0:
|
||||
break
|
||||
for byte in read:
|
||||
if byte_index == 0:
|
||||
pass
|
||||
else:
|
||||
output_tar_fd.write(bytes([byte]))
|
||||
byte_index += 1
|
||||
byte_index %= 5
|
||||
subprocess.Popen(["tar", "xf", input_tar]).wait()
|
||||
print("Done.")
|
||||
|
||||
|
||||
if __name__ == "__main__": main()
|
1
test/.gitignore
vendored
Normal file
1
test/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/wdir
|
1
test/case/a
Normal file
1
test/case/a
Normal file
|
@ -0,0 +1 @@
|
|||
arbre
|
1
test/case/b
Normal file
1
test/case/b
Normal file
|
@ -0,0 +1 @@
|
|||
barbier
|
17
test/run
Executable file
17
test/run
Executable file
|
@ -0,0 +1,17 @@
|
|||
#!/usr/bin/bash
|
||||
cd "$(dirname "$(realpath "$0")")"
|
||||
set -e
|
||||
|
||||
|
||||
|
||||
rm -fr wdir
|
||||
mkdir wdir wdir/in wdir/out
|
||||
cp -r case wdir/in/
|
||||
|
||||
|
||||
cd wdir/in
|
||||
../../../compress.py case
|
||||
cp case.cprmt ../out/
|
||||
|
||||
cd ../out
|
||||
../../../decompr.py case.cprmt
|
Loading…
Add table
Add a link
Reference in a new issue