diff options
author | Daniel Stenberg <daniel@haxx.se> | 2000-11-22 07:27:26 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2000-11-22 07:27:26 +0000 |
commit | a40b55d5c8d3148377a57c4f91364b2bd0f05716 (patch) | |
tree | 7420f2b950d726bced5ed29ce3b79b3f98cef364 | |
parent | 5aa5ecb29b54b9f4c726623b5ad5488d02342ed5 (diff) |
Added 5.2 How can I receive all data into a large memory chunk?
-rw-r--r-- | docs/FAQ | 37 |
1 files changed, 36 insertions, 1 deletions
@@ -1,4 +1,4 @@ -Updated: October 27, 2000 (http://curl.haxx.se/docs/faq.shtml) +Updated: November 22, 2000 (http://curl.haxx.se/docs/faq.shtml) _ _ ____ _ ___| | | | _ \| | / __| | | | |_) | | @@ -48,6 +48,7 @@ FAQ 5. libcurl Issues 5.1 Is libcurl thread safe? + 5.2 How can I receive all data into a large memory chunk? 6. License Issues 6.1 I have a GPL program, can I use the libcurl library? @@ -402,6 +403,40 @@ FAQ README file from those who have used libcurl in a threaded environment, since I haven't and I get this question more and more frequently! + 5.2 How can I receive all data into a large memory chunk? + + You are in full control of the callback function that gets called every time + there is data received from the remote server. You can make that callback do + whatever you want. You do not have to write the receivied data to a file. + + One solution to this problem could be to have a pointer to a struct that you + pass to the callback function. You set the pointer using the + curl_easy_setopt(CURLOPT_FILE) function. Then that pointer will be passed to + the callback instead of a FILE * to a file: + + /* imaginary struct */ + struct MemoryStruct { + char *memory; + size_t size; + }; + + /* imaginary callback function */ + size_t + WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) + { + register int realsize = size * nmemb; + struct MemoryStruct *mem = (struct MemoryStruct *)data; + + mem->memory = (char *)realloc(mem->memory, mem->size + realsize + 1); + if (mem->memory) { + memcpy(&(mem->memory[mem->size]), ptr, realsize); + mem->size += realsize; + mem->memory[mem->size] = 0; + } + return realsize; + } + + 6. License Issues Curl and libcurl are released under the MPL, the Mozilla Public License. To |