__init__.py 585 B

1234567891011121314151617181920212223242526
  1. import datetime
  2. import hashlib
  3. def timestamp():
  4. return int(datetime.datetime.now().timestamp())
  5. def file_hash(path: str, algo: str, block_size: int = 4096):
  6. h = hashlib.new(algo)
  7. with open(path, "rb") as fd:
  8. while True:
  9. data = fd.read(block_size)
  10. if len(data) > 0:
  11. h.update(data)
  12. else:
  13. break
  14. return h.hexdigest()
  15. def file_md5(path, block_size=4096):
  16. return file_hash(path, "md5", block_size)
  17. def file_sha256(path, block_size=4096):
  18. return file_hash(path, "sha256", block_size)