from io import StringIO


def _read_file(filename):
    """
    Read a res2dinv-file and return the header

    Parameters
    ----------
    filename : str
        Data filename

    Returns
    ------
    type : int
        type of array extracted from header
    file_data : :py:class:`StringIO.StringIO`
        content of file in a StringIO object
    """
    # read data from file
    with open(filename, 'r') as fid2:
        abem_data_orig = fid2.read()

    # for easy access, store the data in a StringIO container
    fid = StringIO()
    fid.write(abem_data_orig)
    fid.seek(0)

    # determine type of array
    fid.readline()
    fid.readline()

    file_type = int(fid.readline().strip())

    # reset file pointer
    fid.seek(0)
    return file_type, fid