First stab at splitting:
input_file = open(input_filename, 'rb') blocksize = 4096 chunksize = 1024 * 256 buf = None chunk_num = 0 current_read = 0 output_filename = 'output-chunk-{:04d}'.format(chunk_num) output_file = open(output_filename, 'wb') while buf is None or len(buf) > 0: buf = input_file.read(blocksize) current_read += len(buf) output_file.write(buf) if chunksize <= current_read: output_file.close() current_read = 0 chunk_num += 1 output_filename = 'output-chunk-{:04d}'.format(chunk_num) output_file = open(output_filename, 'wb') output_file.close() input_file.close()
This might get you partway there; adapt as needed.
Merging:
blocksize = 4096 chunk_num = 0 input_filename = 'output-chunk-{:04d}'.format(chunk_num) output_filename = 'reconstructed.bin' output_file = open(output_filename, 'wb') while True: try: input_file = open(input_filename, 'rb') except IOError: break buf = None while buf is None or len(buf) > 0: buf = input_file.read(blocksize) output_file.write(buf) input_file.close() chunk_num += 1 input_filename = 'output-chunk-{:04d}'.format(chunk_num) output_file.close()
splitandcat