import hashlib


def read_hash_local(weights):
    """Reads local SHA256 hash from weights.

    Parameters
    ----------
    weights : str or pathlib.Path
        Path of the file containing weights.

    Returns
    -------
    local_hash : str or None
        SHA256 hash of weights file.

    Notes
    -----
    Returns None if file is not found.
    """
    BUFFER_SIZE = 65536
    sha256 = hashlib.sha256()

    try:
        with open(weights, 'rb') as file_weights:
            while True:
                data = file_weights.read(BUFFER_SIZE)
                if not data:
                    break
                sha256.update(data)
        local_hash = sha256.hexdigest()
    except FileNotFoundError:
        local_hash = None
    return local_hash