cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: question regarding CURLOPT_WRITEFUNCTION & CURLOPT_WRITEDATA

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Mon, 20 Oct 2008 15:38:03 +0200 (CEST)

On Mon, 20 Oct 2008, Jan wrote:

>> You make sure your callback makes it so. Like the getinmemory.c example!
>
> little question regarding this example: is the call of
> curl_easy_setopt<http://curl.haxx.se/lxr/ident?i=curl_easy_setopt>(curl_handle,
> CURLOPT_WRITEDATA <http://curl.haxx.se/lxr/ident?i=CURLOPT_WRITEDATA>, (void
> *)&chunk) needed?

That sets the pointer that gets passed to the callback. You can of course get
away with something else, like a global variable, if you prefer that.

> because WRITEFUNCTION already creates the large chunk.

No it doesn't.

WRITEFUNCTION is an option you use to set the write callback function with.
The callback function gets called numerous times for each download. It does
not create any large chunk.

If you don't set WRITEFUNCTION, it will remain set to the default internal
function and that is fwrite() - which thus assumes that you set WRITEDATA to
be a FILE * to a filen opened for writing. (Although this default action does
not work if you run libcurl as a DLL on Windows.)

> that on the one hand i want to have a look at the content of the chunk (here
> comes getinmemory.c into play) and on the other hand i want to write the
> data to a file where i used WRITEDATA for.

WRITEDATA is just the data pointer passed to the WRITEFUNCTION.

And if you want the data both in memory and on disk and sent to your printer
you just write your callback function to do that.

-- 
  / daniel.haxx.se
Received on 2008-10-20