code: def file_digest(source):
      
      hash_sha256 = hashlib.sha256()
  
      should_close = False
  
      if isinstance(source, six.string_types):
          should_close = True
          source = open(source, 'rb')
  
      for chunk in iter(lambda: source.read(_BUFFER_SIZE), b''):
          hash_sha256.update(chunk)
  
      if should_close:
          source.close()
  
      return hash_sha256.hexdigest()
docs: Calculates SHA256 digest of a file.
  
      Args:
          source: either a file-like object or a path to file