You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
690 B

  1. import struct
  2. def read_chunk(fh, chunk_location):
  3. """
  4. Gets the data for a given chunk pointer
  5. :rtype: bytes
  6. """
  7. fh.seek(chunk_location)
  8. # The chunk metadata is always 16 bytes long
  9. chunk_metadata = fh.read(16)
  10. header, relative_offset, data_length = struct.unpack("IIQ", chunk_metadata)
  11. if header != 0xabeceda:
  12. raise ValueError("The ND2 file seems to be corrupted.")
  13. # We start at the location of the chunk metadata, skip over the metadata, and then proceed to the
  14. # start of the actual data field, which is at some arbitrary place after the metadata.
  15. fh.seek(chunk_location + 16 + relative_offset)
  16. return fh.read(data_length)