GNURLINFO...H_DOWNLOAD(3)

πŸ“¦ version 7.72.0, in nixos 26.05, nixpkgs unstable

✨ NAME ✨

okay so we're on the GNURLINFO...H_DOWNLOAD(3) page from the curl_easy_getinfo options manual, and the main character is CURLINFO_CONTENT_LENGTH_DOWNLOAD β€” literally get content-length of download, bestie. no cap. πŸ’…

πŸŽ€ SYNOPSIS πŸŽ€

       #include <gnurl/curl.h>

       CURLcode curl_easy_getinfo(CURL *handle,
       CURLINFO_CONTENT_LENGTH_DOWNLOAD,
                                  double *content_length);

πŸ’– DESCRIPTION πŸ’–

Pass a pointer to a double to receive the content-length of the download. That's the value read from the Content-Length: field, fr fr. Since 7.19.4, this returns -1 if the size isn't known. 😭

CURLINFO_CONTENT_LENGTH_DOWNLOAD_T(3) is the newer replacement, and it returns a more sensible variable type. iconic behavior, but this one is still here doing its thing. ✨

🌈 PROTOCOLS 🌈

HTTP(S) β€” that's the vibe. πŸ¦‹

πŸ“ EXAMPLE πŸ“

Here's the example, untouched and slaying:

CURL *curl = curl_easy_init();
if(curl) {
  curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");

  /* Perform the request */
  res = curl_easy_perform(curl);

  if(!res) {
    /* check the size */
    double cl;
    res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &cl);
    if(!res) {
      printf("Size: %.0f\n", cl);
    }
  }
}

⭐ AVAILABILITY ⭐

Added in 7.6.1 β€” vintage but still cute. πŸ’–

πŸ‘‘ RETURN VALUE πŸ‘‘

Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not. that's the whole mood. πŸ’…

πŸ¦‹ SEE ALSO πŸ¦‹

go read those too, iykyk. 🫢


xoxo, your Unix bestie πŸ’– β€” this page is from libcurl 7.44.0, dated 1 Sep 2015, and yes the manual-page header energy is GNURLINFO...H_DOWNLOAD(3) all day. periodt. 🌸

πŸ“¦ where this page comes from