import struct


def read_bin_data(f, dtype, data_byte, header_byte=4, footer_byte=4):
    """
    read data from binary file
    This function reads a binary chunk from current position.

    Parameters
    --------
    f : file object
        a file object opened in read only mode.
    dtype : str
        dtype of the binary chunk
    data_byte : int
        length of the binary chunk to read in byte
    header_byte : int, default 4
        length of the header before the binary chunk to read in byte
    footer_byte : int, default 4
        length of the footer after the binary chunk to read in byte

    Returns
    --------
    data : int, str, float, or list
        a data converted by struct.unpack
    """
    f.seek(header_byte, 1)
    data = struct.unpack(dtype, f.read(data_byte))
    f.seek(footer_byte, 1)
    return data