Files
onepilot/common/file_chunker.py
Harald Schäfer a941e8f78f Chunk big model files (#37134)
* file chunking

* try this

* more cleanup

* cleaner
2026-02-09 15:29:50 -08:00

28 lines
666 B
Python

import glob
import os
import sys
from pathlib import Path
CHUNK_SIZE = 49 * 1024 * 1024 # 49MB, under GitHub's 50MB limit
def chunk_file(path):
with open(path, 'rb') as f:
data = f.read()
for i in range(0, len(data), CHUNK_SIZE):
with open(f"{path}.chunk{i // CHUNK_SIZE:02d}", 'wb') as f:
f.write(data[i:i + CHUNK_SIZE])
os.remove(path)
def read_file_chunked(path):
files = sorted(glob.glob(f"{path}.chunk*")) or ([path] if os.path.isfile(path) else [])
if not files:
raise FileNotFoundError(path)
return b''.join(Path(f).read_bytes() for f in files)
if __name__ == "__main__":
for path in sys.argv[1:]:
chunk_file(path)