code: public function downloadOverwrite(string $filePath, string $url, array $headers = []) {
          try {
              error_clear_last();
              $fp = fopen($filePath, 'wb');
              if ($fp === false && ($error = error_get_last())) {
                  throw new IOException($error['message'], $error['type']);
              }
              $c = $this->curlDownloadInit($url, $headers, $fp);
              if (!curl_exec($c)) {
                  throw new CURLException(curl_error($c), curl_errno($c));
              }
          } finally {
              is_resource($c ?? null) && curl_close($c);
              is_resource($fp ?? null) && fclose($fp);
          }
      }
docs: @param string $filePath
  @param string $url
  @param array  $headers
  
  @throws CURLException
  @throws IOException