1CURLOPT_CHUNK_BGN_FUNCTION(3c)url_easy_setopt optionCsURLOPT_CHUNK_BGN_FUNCTION(3)
2
3
4

NAME

6       CURLOPT_CHUNK_BGN_FUNCTION  - callback before a transfer with FTP wild‐
7       cardmatch
8

SYNOPSIS

10       #include <curl/curl.h>
11
12       long chunk_bgn_callback(const void *transfer_info, void *ptr,
13                               int remains);
14
15       CURLcode curl_easy_setopt(CURL *handle, CURLOPT_CHUNK_BGN_FUNCTION,
16                                 chunk_bgn_callback);
17

DESCRIPTION

19       Pass a pointer to your callback function, which should match the proto‐
20       type shown above.
21
22       This  callback  function  gets  called  by libcurl before a part of the
23       stream is going to be transferred (if the transfer supports chunks).
24
25       The transfer_info pointer will point to  a  struct  curl_fileinfo  with
26       details about the file that is about to get transferred.
27
28       This  callback makes sense only when using the CURLOPT_WILDCARDMATCH(3)
29       option for now.
30
31       The target of transfer_info parameter is a  "feature  depended"  struc‐
32       ture. For the FTP wildcard download, the target is curl_fileinfo struc‐
33       ture (see curl/curl.h).  The parameter ptr is a pointer given  by  CUR‐
34       LOPT_CHUNK_DATA(3).  The  parameter  remains  contains number of chunks
35       remaining per the transfer. If the feature is not available, the param‐
36       eter has zero value.
37
38       Return     CURL_CHUNK_BGN_FUNC_OK     if     everything     is    fine,
39       CURL_CHUNK_BGN_FUNC_SKIP if you want to  skip  the  concrete  chunk  or
40       CURL_CHUNK_BGN_FUNC_FAIL   to  tell  libcurl  to  stop  if  some  error
41       occurred.
42

DEFAULT

44       NULL
45

PROTOCOLS

47       FTP
48

EXAMPLE

50       static long file_is_coming(struct curl_fileinfo *finfo,
51                                  struct callback_data *data,
52                                  int remains)
53       {
54         printf("%3d %40s %10luB ", remains, finfo->filename,
55                (unsigned long)finfo->size);
56
57         switch(finfo->filetype) {
58         case CURLFILETYPE_DIRECTORY:
59           printf(" DIR0);
60           break;
61         case CURLFILETYPE_FILE:
62           printf("FILE ");
63           break;
64         default:
65           printf("OTHER0);
66           break;
67         }
68
69         if(finfo->filetype == CURLFILETYPE_FILE) {
70           /* do not transfer files >= 50B */
71           if(finfo->size > 50) {
72             printf("SKIPPED0);
73             return CURL_CHUNK_BGN_FUNC_SKIP;
74           }
75
76           data->output = fopen(finfo->filename, "wb");
77           if(!data->output) {
78             return CURL_CHUNK_BGN_FUNC_FAIL;
79           }
80         }
81
82         return CURL_CHUNK_BGN_FUNC_OK;
83       }
84
85       int main()
86       {
87         /* data for callback */
88         struct callback_data callback_info;
89
90         /* callback is called before download of concrete file started */
91         curl_easy_setopt(curl, CURLOPT_CHUNK_BGN_FUNCTION, file_is_coming);
92         curl_easy_setopt(curl, CURLOPT_CHUNK_DATA, &callback_info);
93       }
94

AVAILABILITY

96       This was added in 7.21.0
97

RETURN VALUE

99       Returns CURLE_OK if the option is supported,  and  CURLE_UNKNOWN_OPTION
100       if not.
101

SEE ALSO

103       CURLOPT_CHUNK_END_FUNCTION(3), CURLOPT_WILDCARDMATCH(3),
104
105
106
107libcurl 7.61.1                   May 31, 2017    CURLOPT_CHUNK_BGN_FUNCTION(3)
Impressum