Python Forum

Full Version: find the header location in a .bin file without reading the whole file at a time
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
The below code is okay to find the header locations in a .bin file. But I don't want to read whole file at a time. Because the header has different byte format. If I read the whole as a uint16, I will not be able to get those bytes(some are uint8 and uint32). What is the solution so that I can read the file to find the header location and then I can assign the datatype for the header for the information. Basically discard all data before the header and read the header(2bytes-2bytes[little endian]-2bytes[big endian]-1bytes-1byte-......) Thanks in advance!!!!

with open(filename, mode='rb') as f:
    b = f.read()
    np_data = np.frombuffer(b, dtype=np.uint16)
    findIndex = np.where(np_data == int("00000050", 16))