AstroJS/botanjs/utils.py

15 lines
362 B
Python

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 ):
return checksum_r( file_path )
def checksum_r( file_path ):
try:
with open( file_path, "rb" ) as f:
return HashFunc( f.read() )
except FileNotFoundError:
return HashFunc( b"" )