2022-08-02 13:35:37 +00:00
|
|
|
from functools import lru_cache
|
|
|
|
from zlib import adler32 as _HashFunc
|
|
|
|
HashFunc = lambda v: hex( _HashFunc( v ) )[2:]
|
|
|
|
|
|
|
|
@lru_cache( maxsize = 1024 )
|
|
|
|
def checksum( file_path ):
|
2024-11-14 07:25:28 +00:00
|
|
|
return checksum_r( file_path )
|
|
|
|
|
|
|
|
def checksum_r( file_path ):
|
2022-08-02 13:35:37 +00:00
|
|
|
try:
|
|
|
|
with open( file_path, "rb" ) as f:
|
|
|
|
return HashFunc( f.read() )
|
|
|
|
except FileNotFoundError:
|
|
|
|
return HashFunc( b"" )
|