<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def hash_file(path, digest=None):
 """Hashes the contents of the file at the given path and returns the hash digest in hex form. If a hashlib message digest is not supplied a new sha1 message digest is used. """

  digest = digest or hashlib.sha1()
  with open(path, 'rb') as fd:
    s = fd.read(8192)
    while s:
      digest.update(s)
      s = fd.read(8192)
  return digest.hexdigest() if PY3 else digest.hexdigest().decode('utf-8')