cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: stop downloading after x bytes?

From: Andrew <andrew_at_donehue.net>
Date: Fri, 06 Jan 2006 21:45:44 +1100
Thanks for both responses :)

If the server doesn't support ranges, would "0-1000" work anyhow? (the client library will know when it has downloaded the first 1000 bytes).  I am happy to test this, but I don't know of any servers off the top of my head that don't support ranges?



Cheers,
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-06