Sakuten/backend

View on GitHub
api/utils.py

Summary

Maintainability
A
0 mins
Test Coverage
import hashlib
import os
__docs__ = """collection of small utilities"""


def calc_sha256(_file):
    """calculate sha256 hash of given file
        Args:
            _file (str): file path
    """
    if not os.path.isfile(_file):
        raise FileNotFoundError

    with open(_file, 'r') as f:
        return hashlib.sha256(f.read().encode()).hexdigest()