curl-library
Re: stop downloading after x bytes?
Date: Tue, 10 Jan 2006 20:21:00 +1100
Hi,
I have tried calling the close function within the writedata
procedure.... however it segfaults :( - Is it possible to close the
connection (without trying to free the structure) from the writedata
call itself (and then free from within the main program)?
Thanks,
Andrew.
Jeff Pohlmeyer wrote:
>>I want to be able to set the size to stop downloading
>>at as a paramater, not a global variable.
>>
>>
>
>
>libcurl doesn't put any restrictions on what your
>CURLOPT_WRITEDATA is. It can be something as simple
>as a FILE pointer, or it could be a pointer to a
>more complex structure...
>
>struct cb_data {
> FILE *f;
> unsigned int bytes_so_far;
> unsigned int max_bytes;
>}
>
>
>curl_easy_setopt(my_curl, CURLOPT_WRITEDATA, &my_cb_data);
>
>
>
>Or, if you can settle for an approximate value, you could
>set CURLOPT_PROGRESSDATA to an int*, and check it inside
>your CURLOPT_PROGRESSFUNCTION.
>
>
>But yes, as Brian said, it is much more polite to request
>the range you want with CURLOPT_RANGE, than to just drop
>the connection. ( That is, if the server supports ranges. )
>
>
>- Jeff
>
>
>
Received on 2006-01-10