import struct import sys import os import random from pathlib import Path def copy_next_chunk(in_file, out_file): chunk_header = in_file.read(8) assert chunk_header[0:4] == b"BINP" size = struct.unpack(" 0: where = random.randrange(total_remaining) i = 0 while where >= in_files_remaining[i]: where -= in_files_remaining[i] i += 1 size = copy_next_chunk(in_files[i], out_file) in_files_remaining[i] -= size total_remaining -= size total_size += size mib = total_size // 1024 // 1024 if mib // 100 != prev_mib // 100: print("Copied {} MiB".format(mib)) prev_mib = mib out_file.close() for in_file in in_files: in_file.close() print("Merged {} bytes".format(total_size)) main()