mirror of
https://gitlab.com/kupfer/kupferbootstrap.git
synced 2025-02-23 05:35:44 -05:00
utils.py: add sha256sum(filepath)
This commit is contained in:
parent
f77aa4f2a2
commit
b31160146b
1 changed files with 12 additions and 0 deletions
12
utils.py
12
utils.py
|
@ -1,5 +1,6 @@
|
||||||
import atexit
|
import atexit
|
||||||
import grp
|
import grp
|
||||||
|
import hashlib
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import pwd
|
import pwd
|
||||||
|
@ -116,3 +117,14 @@ def read_files_from_tar(tar_file: str, files: Sequence[str]) -> Generator[tuple[
|
||||||
fd = index.extractfile(index.getmember(path))
|
fd = index.extractfile(index.getmember(path))
|
||||||
assert fd
|
assert fd
|
||||||
yield path, fd
|
yield path, fd
|
||||||
|
|
||||||
|
|
||||||
|
# stackoverflow magic from https://stackoverflow.com/a/44873382
|
||||||
|
def sha256sum(filename):
|
||||||
|
h = hashlib.sha256()
|
||||||
|
b = bytearray(128 * 1024)
|
||||||
|
mv = memoryview(b)
|
||||||
|
with open(filename, 'rb', buffering=0) as f:
|
||||||
|
while n := f.readinto(mv):
|
||||||
|
h.update(mv[:n])
|
||||||
|
return h.hexdigest()
|
||||||
|
|
Loading…
Add table
Reference in a new issue