Coverage for /Users/jerry/Development/yenta/yenta/utils/files.py: 100%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

13 statements  

1from hashlib import sha1 

2from pathlib import Path 

3 

4 

5def file_hash(path: Path, block_size=65536): 

6 s = sha1() 

7 

8 if path.exists(): 

9 with open(path, 'rb') as f: 

10 stop = False 

11 while not stop: 

12 data = f.read(block_size) 

13 if len(data) > 0: 

14 s.update(data) 

15 else: 

16 stop = True 

17 

18 return s