1--- 2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3SPDX-License-Identifier: curl 4Title: CURLOPT_CHUNK_DATA 5Section: 3 6Source: libcurl 7See-also: 8 - CURLOPT_CHUNK_BGN_FUNCTION (3) 9 - CURLOPT_WILDCARDMATCH (3) 10Protocol: 11 - FTP 12Added-in: 7.21.0 13--- 14 15# NAME 16 17CURLOPT_CHUNK_DATA - pointer passed to the FTP chunk callbacks 18 19# SYNOPSIS 20 21~~~c 22#include <curl/curl.h> 23 24CURLcode curl_easy_setopt(CURL *handle, CURLOPT_CHUNK_DATA, void *pointer); 25~~~ 26 27# DESCRIPTION 28 29Pass a *pointer* that is untouched by libcurl and passed as the ptr 30argument to the CURLOPT_CHUNK_BGN_FUNCTION(3) and 31CURLOPT_CHUNK_END_FUNCTION(3). 32 33# DEFAULT 34 35NULL 36 37# %PROTOCOLS% 38 39# EXAMPLE 40 41~~~c 42#include <stdio.h> 43 44struct callback_data { 45 FILE *output; 46}; 47 48static long file_is_coming(struct curl_fileinfo *finfo, 49 void *ptr, 50 int remains) 51{ 52 struct callback_data *data = ptr; 53 printf("%3d %40s %10luB ", remains, finfo->filename, 54 (unsigned long)finfo->size); 55 56 switch(finfo->filetype) { 57 case CURLFILETYPE_DIRECTORY: 58 printf(" DIR\n"); 59 break; 60 case CURLFILETYPE_FILE: 61 printf("FILE "); 62 break; 63 default: 64 printf("OTHER\n"); 65 break; 66 } 67 68 if(finfo->filetype == CURLFILETYPE_FILE) { 69 /* do not transfer files >= 50B */ 70 if(finfo->size > 50) { 71 printf("SKIPPED\n"); 72 return CURL_CHUNK_BGN_FUNC_SKIP; 73 } 74 75 data->output = fopen(finfo->filename, "wb"); 76 if(!data->output) { 77 return CURL_CHUNK_BGN_FUNC_FAIL; 78 } 79 } 80 81 return CURL_CHUNK_BGN_FUNC_OK; 82} 83 84int main() 85{ 86 /* data for callback */ 87 struct callback_data callback_info; 88 89 CURL *curl = curl_easy_init(); 90 91 /* callback is called before download of concrete file started */ 92 curl_easy_setopt(curl, CURLOPT_CHUNK_BGN_FUNCTION, file_is_coming); 93 curl_easy_setopt(curl, CURLOPT_CHUNK_DATA, &callback_info); 94} 95~~~ 96 97# %AVAILABILITY% 98 99# RETURN VALUE 100 101Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not. 102