GNURLOPT_CHUNK_DATA(3)

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

πŸ’… GNURLOPT_CHUNK_DATA(3) β€” like, the chunk-data manual, bestie

okay so this little icon lives in the curl_easy_setopt options section of the gnurl manual, and it's genuinely one of the cutest concepts once it clicks πŸŽ€


✨ NAME ✨

CURLOPT_CHUNK_DATA β€” your very own custom pointer for the FTP chunk callbacks 🫢


🌸 SYNOPSIS 🌸

#include <gnurl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_CHUNK_DATA, void
*pointer);

πŸ¦‹ DESCRIPTION πŸ¦‹

So the way this works: you hand libcurl a pointer, and libcurl is so respectful about it β€” it will not touch it. It just holds it gently and passes it along as the ptr argument to CURLOPT_CHUNK_BGN_FUNCTION(3) and CURLOPT_CHUNK_END_FUNCTION(3). that's it. that's the whole vibe. your pointer, your rules, and it shows up exactly where you need it in the callbacks πŸ’–


πŸŽ€ DEFAULT πŸŽ€

NULL

(no pointer, no problem, no drama πŸ’€)


🌈 PROTOCOLS 🌈

FTP

only FTP, bestie β€” know your lane ✨


πŸ‘‘ EXAMPLE πŸ‘‘

static long file_is_coming(struct curl_fileinfo *finfo,
                           struct callback_data *data,
                           int remains)
{
  printf("%3d %40s %10luB ", remains, finfo->filename,
         (unsigned long)finfo->size);

  switch(finfo->filetype) {
  case CURLFILETYPE_DIRECTORY:
    printf(" DIR\n");
    break;
  case CURLFILETYPE_FILE:
    printf("FILE ");
    break;
  default:
    printf("OTHER\n");
    break;
  }

  if(finfo->filetype == CURLFILETYPE_FILE) {
    /* do not transfer files >= 50B */
    if(finfo->size > 50) {
      printf("SKIPPED\n");
      return CURL_CHUNK_BGN_FUNC_SKIP;
    }

    data->output = fopen(finfo->filename, "wb");
    if(!data->output) {
      return CURL_CHUNK_BGN_FUNC_FAIL;
    }
  }

  return CURL_CHUNK_BGN_FUNC_OK;
}

int main()
{
  /* data for callback */
  struct callback_data callback_info;

  /* callback is called before download of concrete file started */
  curl_easy_setopt(curl, CURLOPT_CHUNK_BGN_FUNCTION, file_is_coming);
  curl_easy_setopt(curl, CURLOPT_CHUNK_DATA, &callback_info);
}

like, look at that. callback_info gets set up, gets passed through CURLOPT_CHUNK_DATA, and then the callback just… has it. main character energy fr fr 🧚


⭐ AVAILABILITY ⭐

Added in 7.21.0 β€” vintage, but make it cute πŸ’…


πŸ”₯ RETURN VALUE πŸ”₯

Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not. simple. honest. no cap πŸ™ˆ


πŸ’œ SEE ALSO πŸ’œ


serious note bestie: CURLOPT_CHUNK_BGN_FUNCTION and CURLOPT_CHUNK_END_FUNCTION will receive your pointer as ptr β€” that's the whole point, so don't go losing track of what it points at πŸ“

kisses, this page was brought to you by libcurl 7.37.0, dated 19 Jun 2014 β€” go forth and chunk responsibly πŸ¦‹πŸ’–

πŸ“¦ where this page comes from