|
import os |
|
|
|
def split_file(input_file, output_dir, chunk_size): |
|
if not os.path.exists(output_dir): |
|
os.makedirs(output_dir) |
|
|
|
file_size = os.path.getsize(input_file) |
|
base_name = os.path.basename(input_file) |
|
num_chunks = (file_size + chunk_size - 1) // chunk_size |
|
print(f"Total size: {file_size} bytes, split to {num_chunks} files") |
|
|
|
with open(input_file, 'rb') as f: |
|
for i in range(num_chunks): |
|
part_filename = os.path.join(output_dir, f"{base_name}.part{i + 1:03d}") |
|
with open(part_filename, 'wb') as part_file: |
|
bytes_written = 0 |
|
while bytes_written < chunk_size: |
|
buffer = f.read(min(1024 * 1024, chunk_size - bytes_written)) |
|
if not buffer: |
|
break |
|
part_file.write(buffer) |
|
bytes_written += len(buffer) |
|
print(f"Write to: {part_filename} Size: {bytes_written} bytes") |
|
|
|
|
|
if __name__ == '__main__': |
|
input_file = "data/BIOSCAN_1M/split_data/BioScan_data_in_splits.hdf5" |
|
output_dir = "data/BIOSCAN_1M/split_data/splitted_files" |
|
chunk_size = 45 * (1024 ** 3) |
|
split_file(input_file, output_dir, chunk_size) |
|
|