MCPcopy Index your code
hub / github.com/pyload/pyload / compute_checksum

Function compute_checksum

module/plugins/internal/misc.py:946–974  ·  view source on GitHub ↗
(filename, hashtype)

Source from the content-addressed store, hash-verified

944
945
946def compute_checksum(filename, hashtype):
947 file = fs_encode(filename)
948
949 if not exists(file):
950 return None
951
952 buf = fsbsize(filename)
953
954 if hashtype in ("adler32", "crc32"):
955 hf = getattr(zlib, hashtype)
956 last = 0
957
958 with open(file, "rb") as f:
959 for chunk in iter(lambda: f.read(buf), ''):
960 last = hf(chunk, last)
961
962 return "%x" % last
963
964 elif hashtype in hashlib.algorithms_available:
965 h = hashlib.new(hashtype)
966
967 with open(file, "rb") as f:
968 for chunk in iter(lambda: f.read(buf * h.block_size), ''):
969 h.update(chunk)
970
971 return h.hexdigest()
972
973 else:
974 return None
975
976
977def copy_tree(src, dst, overwrite=False, preserve_metadata=False):

Callers

nothing calls this directly

Calls 7

existsFunction · 0.85
fsbsizeFunction · 0.85
hexdigestMethod · 0.80
fs_encodeFunction · 0.70
readMethod · 0.45
newMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected