cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: CURLOPT_WRITEDATA append vs overwrite

From: Ganesh Ragavan <ganeshragavan_at_gmail.com>
Date: Thu, 5 Jun 2008 13:54:39 -0700

Thanks Dan.

I do pass in a valid file descriptor with CURLOPT_WRITEDATA and I fopen the
file with 'w' mode that erases the contents, but this happens outside the
retry loop.

So if curl_easy_perform(curl_desc) fails and before
curl_easy_perform(curl_desc) is called again in the retry loop,
can I do a seek of the file descriptor to point it back to the start of the
file ?

I don't want to go with CURLOPT_RESUME_FROM_LARGE as failures don't happen
frequently.

~Ganesh

On Thu, Jun 5, 2008 at 12:43 PM, Dan Fandrich <dan_at_coneharvesters.com>
wrote:

> 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