GNURLINFO...DOWNLOAD_T(3)

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

πŸ’… CURLINFO_CONTENT_LENGTH_DOWNLOAD_T β€” get content-length of download

okay bestie, so this page lives in the curl_easy_getinfo options family β€” the manual name is literally GNURLINFO...DOWNLOAD_T(3), iconic little corner of the gnurl world. let's get into it πŸŽ€


✨ SYNOPSIS ✨

#include <gnurl/curl.h>

CURLcode curl_easy_getinfo(CURL *handle,
CURLINFO_CONTENT_LENGTH_DOWNLOAD_T,
                           curl_off_t *content_length);

🌸 DESCRIPTION 🌸

so you pass a pointer to a curl_off_t, right? and it gets filled with the content-length of the download. that's the value read straight from the Content-Length: field. and if the size isn't known? it just stores -1. no cap, that's it. πŸ’–


πŸ¦‹ PROTOCOLS πŸ¦‹

HTTP(S) β€” that's the vibe check, only these two πŸ‘‘


⭐ EXAMPLE ⭐

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 */
    curl_off_t cl;
    res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T, &cl);
    if(!res) {
      printf("Download size: %" CURL_FORMAT_CURL_OFF_T "\n", cl);
    }
  }
}

literally the whole glow-up in one snippet 🫢


🌈 AVAILABILITY 🌈

Added in 7.55.0 β€” she's been here a minute, lowkey a legend ✨


πŸ’€ RETURN VALUE πŸ’€

Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not. that's the whole tea β˜•


πŸŽ€ SEE ALSO πŸŽ€


ngl, this one's a short read but it ate. go check your download sizes, bestie πŸ’…

sign-off szn: this page ships with libcurl 7.55.0, dated 25 May 2017 β€” and the manual slot it lives in is GNURLINFO...DOWNLOAD_T(3) πŸ§šπŸ’œ

πŸ“¦ where this page comes from