GNURLOPT_CHUNK_DATA(3)
π 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_FUNCTIONandCURLOPT_CHUNK_END_FUNCTIONwill receive your pointer asptrβ 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
- nixos 26.05: libgnurl 7.72.0
- nixpkgs unstable: libgnurl 7.72.0
- Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms