CURLINFO_SIZE_DOWNLOAD.md (1653B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLINFO_SIZE_DOWNLOAD 5 Section: 3 6 Source: libcurl 7 See-also: 8 - CURLINFO_SIZE_DOWNLOAD_T (3) 9 - CURLINFO_SIZE_UPLOAD_T (3) 10 - CURLOPT_MAXFILESIZE (3) 11 - curl_easy_getinfo (3) 12 - curl_easy_setopt (3) 13 Protocol: 14 - All 15 Added-in: 7.4.1 16 --- 17 18 # NAME 19 20 CURLINFO_SIZE_DOWNLOAD - get the number of downloaded bytes 21 22 # SYNOPSIS 23 24 ~~~c 25 #include <curl/curl.h> 26 27 CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_SIZE_DOWNLOAD, double *dlp); 28 ~~~ 29 30 # DESCRIPTION 31 32 Pass a pointer to a double to receive the total amount of bytes that were 33 downloaded. The amount is only for the latest transfer and gets reset again 34 for each new transfer. This counts actual payload data, what's also commonly 35 called body. All meta and header data is excluded and not included in this 36 number. 37 38 CURLINFO_SIZE_DOWNLOAD_T(3) is a newer replacement that returns a more 39 sensible variable type. 40 41 # %PROTOCOLS% 42 43 # EXAMPLE 44 45 ~~~c 46 int main(void) 47 { 48 CURL *curl = curl_easy_init(); 49 if(curl) { 50 CURLcode res; 51 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); 52 53 /* Perform the request */ 54 res = curl_easy_perform(curl); 55 56 if(!res) { 57 /* check the size */ 58 double dl; 59 res = curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, &dl); 60 if(!res) { 61 printf("Downloaded %.0f bytes\n", dl); 62 } 63 } 64 } 65 } 66 ~~~ 67 68 # DEPRECATED 69 70 Deprecated since 7.55.0. 71 72 # %AVAILABILITY% 73 74 # RETURN VALUE 75 76 curl_easy_setopt(3) returns a CURLcode indicating success or error. 77 78 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see 79 libcurl-errors(3).