![]() |
Fun 0.41.5
The programming language that makes you have fun!
|
Fun VM opcode snippet: HTTP download to file via libcurl (OP_CURL_DOWNLOAD). More...
Go to the source code of this file.
Functions | |
| free_value (vurl) | |
| free_value (vpath) | |
| if (!url||!path) | |
| if (!fp) | |
| curl_easy_setopt (h, CURLOPT_URL, url) | |
| curl_easy_setopt (h, CURLOPT_FOLLOWLOCATION, 1L) | |
| curl_easy_setopt (h, CURLOPT_WRITEFUNCTION, fun_curl_file_write_cb) | |
| curl_easy_setopt (h, CURLOPT_WRITEDATA, fp) | |
| curl_easy_cleanup (h) | |
| fclose (fp) | |
| free (url) | |
| free (path) | |
| if (rc !=CURLE_OK) | |
| push_value (vm, make_int(1)) | |
Variables | |
| case | OP_CURL_DOWNLOAD |
| Value | vurl = pop_value(vm) |
| char * | url = value_to_string_alloc(&vurl) |
| char * | path = value_to_string_alloc(&vpath) |
| FILE * | fp = fopen(path, "wb") |
| CURL * | h = curl_easy_init() |
| CURLcode | rc = curl_easy_perform(h) |
| break | |
Fun VM opcode snippet: HTTP download to file via libcurl (OP_CURL_DOWNLOAD).
This snippet is included by vm.c and implements the OP_CURL_DOWNLOAD instruction. When FUN_WITH_CURL is enabled, it downloads the content at the given URL and writes it to the specified filesystem path.
Stack behavior:
Pops a destination path and URL, streams the HTTP response body into the file, and pushes 1 on success or 0 on any error. Without FUN_WITH_CURL, behaves as a no-op that consumes two values and pushes 0.
Error handling:
Notes:
Definition in file download.c.
| curl_easy_cleanup | ( | h | ) |
| curl_easy_setopt | ( | h | , |
| CURLOPT_FOLLOWLOCATION | , | ||
| 1L | ) |
| curl_easy_setopt | ( | h | , |
| CURLOPT_WRITEFUNCTION | , | ||
| fun_curl_file_write_cb | ) |
| fclose | ( | fp | ) |
| free | ( | path | ) |
| free | ( | url | ) |
| free_value | ( | vpath | ) |
| free_value | ( | vurl | ) |
| if | ( | ! | fp | ) |
Definition at line 53 of file download.c.
| if | ( | !url||! | path | ) |
Definition at line 46 of file download.c.
| if | ( | rc ! | = CURLE_OK | ) |
Definition at line 76 of file download.c.
| push_value | ( | vm | , |
| make_int(1) | ) |
| break |
Definition at line 88 of file download.c.
| FILE* fp = fopen(path, "wb") |
Definition at line 52 of file download.c.
| CURL* h = curl_easy_init() |
Definition at line 59 of file download.c.
| case OP_CURL_DOWNLOAD |
Definition at line 38 of file download.c.
| char* path = value_to_string_alloc(&vpath) |
Definition at line 43 of file download.c.
| void rc = curl_easy_perform(h) |
Definition at line 71 of file download.c.
| char* url = value_to_string_alloc(&vurl) |
Definition at line 42 of file download.c.
Definition at line 41 of file download.c.