utils.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:RKSV 作者: ztp-at 项目源码 文件源码
def skipBOM(fd):
    """
    Removes the BOM from UTF-8 files so that we can live in peace.
    :param fd: The file descriptor that may or may not have a BOM at the start.
    :return: The position after the BOM as reported by fd.tell().
    """
    try:
        pos = fd.tell()
    except IOError:
        return 0

    if isinstance(fd, io.TextIOBase):
        fst = fd.read(len(codecs.BOM_UTF8.decode('utf-8')))
        if fst.encode('utf-8') != codecs.BOM_UTF8:
            fd.seek(pos)
    else:
        fst = fd.read(len(codecs.BOM_UTF8))
        if fst != codecs.BOM_UTF8:
            fd.seek(pos)

    return fd.tell()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号