code: def write_and_get_hash(path, write_to_file, hash=None):
      
      hash = hash or hashlib.md5()
      try:
          # Access path
          r = config.DOWNLOAD_SESSION.get(path, stream=True)
          r.raise_for_status()
          for chunk in r:
              write_to_file.write(chunk)
              hash.update(chunk)
  
      except (MissingSchema, InvalidSchema):
          # If path is a local file path, try to open the file (generate hash if none provided)
          with open(path, 'rb') as fobj:
              for chunk in iter(lambda: fobj.read(2097152), b""):
                  write_to_file.write(chunk)
                  hash.update(chunk)
  
      assert write_to_file.tell() > 0, "File failed to write (corrupted)."
  
      return hash
docs: write_and_get_hash: write file
          Args: None
          Returns: Hash of file's contents