cURL / Mailing Lists / curl-library / Single Mail

curl-library

CURLOPT_WRITEDATA append vs overwrite

From: Ganesh Ragavan <ganeshragavan_at_gmail.com>
Date: Thu, 5 Jun 2008 12:18:01 -0700

Hi All,

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 ?

Following is the code sample:

curl_easy_setopt(curl_desc,
           CURLOPT_WRITEDATA,
           pFile);
for (i=0; i<4; i++) {
        res = curl_easy_perform(curl_desc);
        if (res != CURLE_OK ) {
            sleep(10);
        }
        else {
            break;
        }
    }

Thanks for your help.
~G
Received on 2008-06-05