CURLOPT_CHUNK_DATA(3)
π CURLOPT_CHUNK_DATA β bestie, it's literally just a pointer you hand to your chunk callbacks
okay so real talk: CURLOPT_CHUNK_DATA(3) is the curl_easy_setopt option that lets you smuggle your own pointer into the FTP chunk callbacks. That's it. That's the whole vibe. This page lives in the Library Functions Manual, and it's short and sweet and honestly kind of iconic for it. π
β¨ SYNOPSIS β¨
#include <curl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_CHUNK_DATA, void *pointer);
like, one function call. one pointer. we love a low-effort queen. π
πΈ DESCRIPTION πΈ
You pass in a pointer, and here's the slay part: libcurl does not touch it. Not even a little. It's untouched, unbothered, moisturised, in its lane. π§ββοΈ
That pointer then gets handed straight to your callbacks as the ptr argument β specifically to the ones you set with CURLOPT_CHUNK_BGN_FUNCTION(3) and CURLOPT_CHUNK_END_FUNCTION(3).
so likeβ¦ it's your little bag of stuff π β your FILE *, your state struct, whatever β riding along into callback land. no cap, that's the entire functionality.
π¦ DEFAULT π¦
NULL
(as in, nothing. nada. the void. π if you don't set it, your ptr is just NULL, so don't be surprised.)
π PROTOCOLS π
This functionality affects ftp only. ftp girlies only, everyone else go home. π
π EXAMPLE π
okay so here's the full glow-up example, copied exactly, no cap:
#include <stdio.h>
struct callback_data {
FILE *output;
};
static long file_is_coming(struct curl_fileinfo *finfo,
void *ptr,
int remains)
{
struct callback_data *data = ptr;
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;
CURL *curl = curl_easy_init();
/* 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);
}
see how callback_info just vibes its way into file_is_coming as ptr, and then gets cast back to struct callback_data *data? that's the whole trick, iykyk. π«Ά
β AVAILABILITY β
Added in curl 7.21.0 β a genuine vintage icon, honestly. π°οΈ
π RETURN VALUE π
curl_easy_setopt(3) returns a CURLcode indicating success or error.
CURLE_OK(0) means everything was OK β¨- non-zero means an error occurred π β go check
libcurl-errors(3)for the deets
π SEE ALSO π
ngl bestie, this one is a "pass your own stuff through" option and nothing more. no hidden lore, no surprise behaviour, just a pointer and a dream. π§
with love, from the libcurl girlies β this page is dated 2026-10-12 and it ate, no crumbs. periodt. π
π¦ where this page comes from
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms