diff --git a/requester.cpp b/requester.cpp index 5899762..c5fdacb 100644 --- a/requester.cpp +++ b/requester.cpp @@ -17,10 +17,8 @@ extern sc::logger logger; size_t requester::write_data(char *buf, size_t sz, size_t nmemb, void *user_data) { size_t realsize = sz * nmemb; SCInfo(logger, "received ", realsize, " bytes"); - std::vector* dest {reinterpret_cast*>(user_data)}; - size_t oldsize = dest->size(); - dest->resize(oldsize + realsize); - std::memcpy(dest->data() + oldsize, buf, realsize); + std::string* text {reinterpret_cast(user_data)}; + text->append(buf, realsize); return realsize; } @@ -35,11 +33,10 @@ requester::~requester() { } std::string requester::get(const std::string &url) { + std::string text; curl_easy_setopt(_h.get(), CURLOPT_URL, url.c_str()); - std::vector buf; - curl_easy_setopt(_h.get(), CURLOPT_WRITEDATA, &buf); + curl_easy_setopt(_h.get(), CURLOPT_WRITEDATA, &text); auto success = curl_easy_perform(_h.get()); if (success != CURLE_OK) throw std::runtime_error("could not get remote data"); - std::string text {buf.data(), buf.size()}; return text; }