misc.py 文件源码

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

项目:pyload-plugins 作者: pyload 项目源码 文件源码
def compute_checksum(filename, hashtype):
    file = encode(filename)

    if not exists(file):
        return None

    buf = fsbsize(filename)

    if hashtype in ("adler32", "crc32"):
        hf = getattr(zlib, hashtype)
        last = 0

        with open(file, "rb") as f:
            for chunk in iter(lambda: f.read(buf), ''):
                last = hf(chunk, last)

        return "%x" % last

    elif hashtype in hashlib.algorithms_available:
        h = hashlib.new(hashtype)

        with open(file, "rb") as f:
            for chunk in iter(lambda: f.read(buf * h.block_size), ''):
                h.update(chunk)

        return h.hexdigest()

    else:
        return None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号