def detect_encoding_and_remove_bom(buf, default_encoding='UTF-8'):
    """
    :param buf: Binary file contents with an optional BOM prefix.
    :param default_encoding: The encoding to be used if the buffer
    doesn't have a BOM prefix.
    :return: (buf_without_bom_prefix, encoding)
    """
    if not isinstance(buf, bytes):
        raise TypeError('buf should be a bytes instance but it is a %s: ' % type(buf).__name__)
    for bom, encoding in _byte_order_marks:
        if buf.startswith(bom):
            return buf[len(bom):], encoding
    return buf, default_encoding
:param buf: Binary file contents with an optional BOM prefix.
    :param default_encoding: The encoding to be used if the buffer
    doesn't have a BOM prefix.
    :return: (buf_without_bom_prefix, encoding)