cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: CURLOPT_WRITEDATA append vs overwrite

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Thu, 5 Jun 2008 12:43:48 -0700

On Thu, Jun 05, 2008 at 12:18:01PM -0700, Ganesh Ragavan wrote:
> I am using curl_easy_perform(curl_desc) to fetch bytes of size say 1000 bytes
> from the server and writing the output to a file. Following is my scenario:
>
> 1. After 500 bytes are read, the server goes down
> 2. curl_easy_perform returns error
> 3. The output file now contains 500 bytes.
> 4. I am invoking curl_easy_perform(curl_desc) again in a loop.
> 5. When the server comes back up, curl_easy_perform(curl_desc) reads 1000 bytes
> and appends it to the output file.
> 6. The ouput file is now of size 1500 bytes.
>
> Is there any way to prevent the bytes from getting appended to the output file
> and rather overwrite the file everytime curl_easy_setopt is called ?

It's your program's responsibility to pass in a valid file descriptor
with CURLOPT_WRITEDATA, so you need to open that file with an option that
erases any previous contents. But better yet, you could do the equivalent
of the command-line's --continue-at option (CURLOPT_RESUME_FROM_LARGE)
to just download the data that hasn't yet been downloaded. The logic to
do this right is more complicated, but it can save downloading time if
failures happen frequently.

>>> Dan

-- 
http://www.MoveAnnouncer.com              The web change of address service
          Let webmasters know that your web site has moved
Received on 2008-06-05