cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: question regarding CURLOPT_WRITEFUNCTION & CURLOPT_WRITEDATA

From: Ralph Mitchell <ralphmitchell_at_gmail.com>
Date: Tue, 21 Oct 2008 09:07:04 -0500

On Tue, Oct 21, 2008 at 6:22 AM, Jan <haihappn_at_gmail.com> wrote:

>
>
> 2008/10/21 Nikolai Kondrashov <Nikolai.Kondrashov_at_oktetlabs.ru>
>
>
>> Are you interpreting it as a zero-terminated string?
>>
>
> Well, i think so, because the struct uses a char pointer to store the
> content of the chunk. the solution would be to change the struct in a way so
> that it accepts also binary data, but it dont exactly know how to do this..
>

What needs to be changed?? I've just extracted the getinmemory.c example
from the curl-7.18.2 tarball, altered the url to pick up the "powered by
apache" PNG file from my local server, and added these lines right before
"chunk" struct is freed:

     FILE *p;
     p=fopen("/tmp/image.png", "w");
     fwrite(chunk.memory, sizeof (char), chunk.size, p);
     fclose(p);

The md5sum of the new file, /tmp/image.png, exactly matches the original and
it displays just fine. Seems to me like getinmemory.c does a fine job of
grabbing a binary file.

Ralph Mitchell
Received on 2008-10-21