cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: How to write from buffer to file

From: Joe N. <jnardone_at_gmail.com>
Date: Sat, 12 Jul 2008 09:36:45 -0400

> Thanks allot Joe N. But if we set a file pointer fp like below ;
>
> fp= fopen("abc.txt", "w");
>
> curl_easy_setopt(curl_handler, CURLOPT_WRITEDATA, fp);
>
> Then it is going to copy data coming from server or out side source.
>
> First doubt: If we have buffer like char Data_recv[10240] having some
> content. If we want to write content of Data_recv[] buffer to file. How we
> will write content of Data_recv[] to file using curl api.
>
>
Where is this buffer coming from? Reading and writing from buffers to
disk is not really a libCURL thing, but standard IO. What am I missing?
> Second doubt: If we have File(abc.txt). We to read this file content into
> one buffer char read_data[10240].Is it possible to read using curl api.
>
>
Again, this is standard IO.

> Third API: Is correct below option:
>
> curl_easy_setopt(curl_handler, CURLOPT_READDATA, buffer);
>
> here char buffer[10240];
>
> but here how curl is going to recognize to which file(file name) is going
> to read.
>
If you want to use libCURL to read/write into a buffer instead of a
file, then you need to supply your own callback and custom function for
reading/writing into that buffer. The callback will tell you how many
bytes are being returned this particular call into the callback, it is
up to you to manage the size of your buffer and the position within that
buffer. Remember that the callback can be called many times for a
single transfer.

When dealing with a buffer, there are no files. If you want to later
write the buffer to a file, that is outside the scope of libCURL.

joe
Received on 2008-07-12