I am trying to unpack a file containing over 1 billion bytes that encode integers which are 4 bytes each. So every 4 bytes is a different integer. I obviously need to chunk my code for such a big file. I currently have the following:-
import os
z =os.path.getsize(x)
import struct
with open(x, "rb") as f:
while True:
this_chunk = min(50000000, z)
data = f.read(this_chunk)
ints1 = struct.unpack("I" * (this_chunk //4) , data)
if not data:
break
print(ints1)
I get an error which reads:-
struct.error: unpack requires a bytes object of length 50000000
Could you please help me understand this error and how to fix it? Thank you!