curl-library
RE: stop downloading after x bytes?
Date: Fri, 6 Jan 2006 03:58:00 -0600
> 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-06