:param buf: Binary file contents with optional BOM prefix.
    :param default_encoding: The encoding to be used if the buffer
    doesn't have a BOM prefix.
    :param use_utf8_strings: Used only in case of python2: You can choose utf-8
    str in-memory string representation in case of python. If use_utf8_strings is
    False or you are using python3 then the text buffer is automatically loaded as a
    unicode object.
    :return: A unicode object. In case of python2 it can optionally be an str object
    containing utf-8 encoded text.

def decode_utf_text_buffer(buf, default_encoding='UTF-8', use_utf8_strings=True):
    """
    :param buf: Binary file contents with optional BOM prefix.
    :param default_encoding: The encoding to be used if the buffer
    doesn't have a BOM prefix.
    :param use_utf8_strings: Used only in case of python2: You can choose utf-8
    str in-memory string representation in case of python. If use_utf8_strings is
    False or you are using python3 then the text buffer is automatically loaded as a
    unicode object.
    :return: A unicode object. In case of python2 it can optionally be an str object
    containing utf-8 encoded text.
    """
    buf, encoding = detect_encoding_and_remove_bom(buf, default_encoding)
    if python2 and use_utf8_strings:
        if are_encoding_names_equivalent(encoding, 'UTF-8'):
            return buf
        return buf.decode(encoding).encode('UTF-8')
    return buf.decode(encoding)