forked from importers/git-importer
Migrate the ProxySHA256 data into postgresql DB
The calculation of the sha256 and the mimetype is local due to that
This commit is contained in:
20
lib/hash.py
Normal file
20
lib/hash.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import functools
|
||||
import hashlib
|
||||
|
||||
|
||||
def _hash(hash_alg, file_or_path):
|
||||
h = hash_alg()
|
||||
|
||||
def __hash(f):
|
||||
while chunk := f.read(1024 * 4):
|
||||
h.update(chunk)
|
||||
|
||||
if hasattr(file_or_path, "read"):
|
||||
__hash(file_or_path)
|
||||
else:
|
||||
with file_or_path.open("rb") as f:
|
||||
__hash(f)
|
||||
return h.hexdigest()
|
||||
|
||||
|
||||
md5 = functools.partial(_hash, hashlib.md5)
|
Reference in New Issue
Block a user