def checksum_file(summer, path):
  """
  Calculates the checksum of the file 'path' using the provided hashlib
  digest implementation. Returns the hex form of the digest.
  """
  with open(path, "rb") as f:
    # Read the file in 4KB chunks until EOF.
    while True:
      chunk = f.read(4096)
      if not chunk:
        break
      summer.update(chunk)
  return summer.hexdigest()