original_string: public function download_one($url, $params, $options = array()) {
          $options['CURLOPT_HTTPGET'] = 1;
          if (!empty($params)) {
              $url .= (stripos($url, '?') !== false) ? '&' : '?';
              $url .= http_build_query($params, '', '&');
          }
          if (!empty($options['filepath']) && empty($options['file'])) {
              // open file
              if (!($options['file'] = fopen($options['filepath'], 'w'))) {
                  $this->errno = 100;
                  return get_string('cannotwritefile', 'error', $options['filepath']);
              }
              $filepath = $options['filepath'];
          }
          unset($options['filepath']);
          $result = $this->request($url, $options);
          if (isset($filepath)) {
              fclose($options['file']);
              if ($result !== true) {
                  unlink($filepath);
              }
          }
          return $result;
      }
code: public function download_one($url, $params, $options = array()) {
          $options['CURLOPT_HTTPGET'] = 1;
          if (!empty($params)) {
              $url .= (stripos($url, '?') !== false) ? '&' : '?';
              $url .= http_build_query($params, '', '&');
          }
          if (!empty($options['filepath']) && empty($options['file'])) {
              // open file
              if (!($options['file'] = fopen($options['filepath'], 'w'))) {
                  $this->errno = 100;
                  return get_string('cannotwritefile', 'error', $options['filepath']);
              }
              $filepath = $options['filepath'];
          }
          unset($options['filepath']);
          $result = $this->request($url, $options);
          if (isset($filepath)) {
              fclose($options['file']);
              if ($result !== true) {
                  unlink($filepath);
              }
          }
          return $result;
      }
code_tokens: public function download_one ( $ url , $ params , $ options = array ( ) ) { $ options [ 'CURLOPT_HTTPGET' ] = 1 ; if ( ! empty ( $ params ) ) { $ url .= ( stripos ( $ url , '?' ) !== false ) ? '&' : '?' ; $ url .= http_build_query ( $ params , '' , '&' ) ; } if ( ! empty ( $ options [ 'filepath' ] ) && empty ( $ options [ 'file' ] ) ) { // open file if ( ! ( $ options [ 'file' ] = fopen ( $ options [ 'filepath' ] , 'w' ) ) ) { $ this -> errno = 100 ; return get_string ( 'cannotwritefile' , 'error' , $ options [ 'filepath' ] ) ; } $ filepath = $ options [ 'filepath' ] ; } unset ( $ options [ 'filepath' ] ) ; $ result = $ this -> request ( $ url , $ options ) ; if ( isset ( $ filepath ) ) { fclose ( $ options [ 'file' ] ) ; if ( $ result !== true ) { unlink ( $ filepath ) ; } } return $ result ; }
docstring: Downloads one file and writes it to the specified file handler
  
  <code>
  $c = new curl();
  $file = fopen('savepath', 'w');
  $result = $c->download_one('http://localhost/', null,
  array('file' => $file, 'timeout' => 5, 'followlocation' => true, 'maxredirs' => 3));
  fclose($file);
  $download_info = $c->get_info();
  if ($result === true) {
  // file downloaded successfully
  } else {
  $error_text = $result;
  $error_code = $c->get_errno();
  }
  </code>
  
  <code>
  $c = new curl();
  $result = $c->download_one('http://localhost/', null,
  array('filepath' => 'savepath', 'timeout' => 5, 'followlocation' => true, 'maxredirs' => 3));
  // ... see above, no need to close handle and remove file if unsuccessful
  </code>
  
  @param string $url
  @param array|null $params key-value pairs to be added to $url as query string
  @param array $options request options. Must include either 'file' or 'filepath'
  @return bool|string true on success or error string on failure
docstring_tokens: Downloads one file and writes it to the specified file handler