Python Forum
find the header location in a .bin file without reading the whole file at a time
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
find the header location in a .bin file without reading the whole file at a time
#1
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))
Larz60+ write Mar-05-2021, 04:21 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.
Also fixed indentation
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with reading json file hhchenfx 5 284 Jul-07-2021, 01:58 PM
Last Post: hhchenfx
  [Solved] Reading every nth line into a column from txt file Laplace12 7 466 Jun-29-2021, 09:17 AM
Last Post: Laplace12
  help with project of reading and searching big log file korenron 6 265 Jun-24-2021, 01:57 PM
Last Post: korenron
  Read file, reformat and write new file bryanmartin113 1 339 Jun-08-2021, 09:27 PM
Last Post: Larz60+
  How to save modification of a file in original file not a new one? mjrezayani 3 560 Jun-04-2021, 01:28 PM
Last Post: snippsat
  Check last time file was accessed Pavel_47 4 473 Jun-01-2021, 05:47 PM
Last Post: Yoriz
  Helps with reading csv file - 3 methods hhchenfx 4 479 May-13-2021, 04:15 AM
Last Post: buran
  Subprocess.Popen() not working when reading file path from csv file herwin 13 1,132 May-07-2021, 03:26 PM
Last Post: herwin
  code for CSV file to html file without pandas jony057 1 460 Apr-24-2021, 09:41 PM
Last Post: snippsat
  Copy column from one existing excel file to another file mkujawsk 0 480 Apr-14-2021, 06:33 PM
Last Post: mkujawsk

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020