-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhuffman.py
executable file
·42 lines (32 loc) · 1.17 KB
/
huffman.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/local/bin/python3
import sys
import argparse
import shutil
def encode(input_file, output_file):
print("encoding ", input_file, output_file)
# write code here
# simply copying the file to bypass the actual test.
# remove the below lines.
if input_file != "" and output_file != "":
shutil.copyfile(input_file, output_file)
def decode(input_file, output_file):
print("decoding ", input_file, output_file)
# write code here
# simply copying the file to bypass the actual test.
# remove the below lines.
if input_file != "" and output_file != "":
shutil.copyfile(input_file, output_file)
def get_options(args=sys.argv[1:]):
parser = argparse.ArgumentParser(description="Huffman compression.")
groups = parser.add_mutually_exclusive_group(required=True)
groups.add_argument("-e", type=str, help="Encode files")
groups.add_argument("-d", type=str, help="Decode files")
parser.add_argument("-o", type=str, help="Write encoded/decoded file", required=True)
options = parser.parse_args()
return options
if __name__ == "__main__":
options = get_options()
if options.e is not None:
encode(options.e, options.o)
if options.d is not None:
decode(options.d, options.o)