MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / init

Method init

smallthinker/tools/run/run.cpp:400–443  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

398class HttpClient {
399 public:
400 int init(const std::string & url, const std::vector<std::string> & headers, const std::string & output_file,
401 const bool progress, std::string * response_str = nullptr) {
402 if (std::filesystem::exists(output_file)) {
403 return 0;
404 }
405
406 std::string output_file_partial;
407 curl = curl_easy_init();
408 if (!curl) {
409 return 1;
410 }
411
412 progress_data data;
413 File out;
414 if (!output_file.empty()) {
415 output_file_partial = output_file + ".partial";
416 if (!out.open(output_file_partial, "ab")) {
417 printe("Failed to open file for writing\n");
418
419 return 1;
420 }
421
422 if (out.lock()) {
423 printe("Failed to exclusively lock file\n");
424
425 return 1;
426 }
427 }
428
429 set_write_options(response_str, out);
430 data.file_size = set_resume_point(output_file_partial);
431 set_progress_options(progress, data);
432 set_headers(headers);
433 CURLcode res = perform(url);
434 if (res != CURLE_OK){
435 printe("Fetching resource '%s' failed: %s\n", url.c_str(), curl_easy_strerror(res));
436 return 1;
437 }
438 if (!output_file.empty()) {
439 std::filesystem::rename(output_file_partial, output_file);
440 }
441
442 return 0;
443 }
444
445 ~HttpClient() {
446 if (chunk) {

Callers

nothing calls this directly

Calls 5

printeFunction · 0.85
emptyMethod · 0.45
openMethod · 0.45
lockMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected