def _hash_file(filename, block_size, hashobj):
    """Helper function: Initialize a hash obj and digests a file through it.
    Calculates an md5sum based on the contents of the filename by calling digest()

    :param filename: Name of the file to calculate hash value
    :type filename: String
    :param block_size: How many bytes of the file you want to open at a time
    :type block_size: Integer
    :param hashobj: Type of algorithm to calculate hash
    :type hashobj: Hash
    :return: Returns the hash value in hexadecimal format
    :rtype: hex
    """
    with open(filename, 'rb') as f:
        for block in iter(lambda: f.read(block_size), b''):
            hashobj.update(block)
    return hashobj.hexdigest()