15 lines
389 B
Python
15 lines
389 B
Python
import hashlib
|
|
import re
|
|
|
|
from fastapi import UploadFile
|
|
|
|
|
|
safeName = re.compile(r"[^\w\d\.-]")
|
|
|
|
# If this gets too out of hand, put an async breakpoint to allow other things to be handled while the hash occurs
|
|
async def SHA256(f: UploadFile) -> str:
|
|
sha = hashlib.sha256()
|
|
while data := await f.read(65535):
|
|
sha.update(data)
|
|
await f.seek(0)
|
|
return sha.hexdigest()
|