docs: def _write_file_safely(local_path, fileinfo, response):
      """attempts to stream a remote file into a local file object,
      removes the local file if it's interrupted by any error"""
      try:
          _write_file(local_path, fileinfo, response)
      except BaseException as e:
          logger.warning("{} interrupted writing {} -- "
                         "cleaning up partial file".format(
                         e.__class__.__name__, local_path))
          os.remove(local_path)
          raise e