File size: 1,449 Bytes
20d0351
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import sys
import argparse
import tarfile
import concurrent.futures

IMAGE_DIR = "images"
COMPRESSED_DIR = "compressed"

def decompress_chunk(chunk_file, output_dir):
    with tarfile.open(chunk_file, "r:gz") as tar:
        tar.extractall(path=output_dir)

def parse_args():
    parser = argparse.ArgumentParser(description="Decompress chunked archives.")
    parser.add_argument("-i", "--input-dir", default=COMPRESSED_DIR, help="Input directory containing compressed chunks")
    parser.add_argument("-o", "--output-dir", default=IMAGE_DIR, help="Output directory for decompressed files")
    args = parser.parse_args()
    return args

def main():
    args = parse_args()
    if not os.path.exists(args.input_dir):
        print(f"Input directory \"{args.input_dir}\" does not exist.")
        sys.exit(1)
    chunk_files = [os.path.join(args.input_dir, f) for f in os.listdir(args.input_dir) if f.endswith(".tar.gz")]
    os.makedirs(args.output_dir, exist_ok=True)
    with concurrent.futures.ThreadPoolExecutor(max_workers=os.cpu_count()) as executor:
        futures = []
        for chunk_file in chunk_files:
            future = executor.submit(decompress_chunk, chunk_file, args.output_dir)
            futures.append(future)
        concurrent.futures.wait(futures)

if __name__ == "__main__":
    try:
        main()
    except KeyboardInterrupt:
        print("\nScript interrupted by user, exiting...")
        sys.exit(1)