import io


def open_utf8(file, mode='r'):
    """ Open a stream for read or write with UTF-8 encoding.

    Args:
        file:  File to open
        mode:  Open mode
    """
    encd = 'utf-8-sig' if mode.startswith('r') else 'utf-8'
    return io.open(file, mode=mode, encoding=encd, errors='ignore')