def METHOD_NAME(filename, size=None):
    """read text from a file as string
    Argument
    --------
    filename  (str or file): name of file to read or file-like object
    size  (int or None): number of bytes to read
    Returns
    -------
    text of file as string.
    Notes
    ------
    1. the encoding is detected with charset_normalizer.from_bytes
       which is then used to decode bytes read from file.
    2. line endings are normalized to be '\n', so that
       splitting on '\n' will give a list of lines.
    3. if filename is given, it can be a gzip-compressed file
    """
    text = ''
    def decode(bytedata):
        return str(from_bytes(bytedata).best())
    if isinstance(filename, io.IOBase):
        text = filename.read(size)
        if filename.mode == 'rb':
            text = decode(text)
    else:
        fopen = GzipFile if is_gzip(filename) else open
        with fopen(filename, 'rb') as fh:
            text = decode(fh.read(size))
    return text.replace('\r\n', '\n').replace('\r', '\n')