def read_bin_fragment(struct_def, fileh, offset=0, data=None, byte_padding=None):
 if (data is None):
  data = {}
 bytes_read = 0
 for item in struct_def:
  fileh.seek((offset + bytes_read))
  n_bytes = struct.calcsize(item[1])
  buffer = fileh.read(n_bytes)
  read = struct.unpack(('>' + item[1]), buffer)
  if (len(read) == 1):
   read = read[0]
  data[item[0]] = read
  bytes_read += n_bytes
 if (byte_padding is not None):
  pad = byte_padding
  bytes_read = ((((bytes_read + pad) - 1) // pad) * pad)
 return (bytes_read, data)

def read_bin_fragment ( struct_def , fileh , offset = 0 , data = None , byte_padding = None ) : if ( data is None ) : data = { } bytes_read = 0 for item in struct_def : fileh . seek ( ( offset + bytes_read ) ) n_bytes = struct . calcsize ( item [ 1 ] ) buffer = fileh . read ( n_bytes ) read = struct . unpack ( ( '>' + item [ 1 ] ) , buffer ) if ( len ( read ) == 1 ) : read = read [ 0 ] data [ item [ 0 ] ] = read bytes_read += n_bytes if ( byte_padding is not None ) : pad = byte_padding bytes_read = ( ( ( ( bytes_read + pad ) - 1 ) // pad ) * pad ) return ( bytes_read , data )
it reads a chunk of a binary file .