cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: how to download first 100 bytes

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Sat, 11 Jun 2011 11:03:54 -0700

On Sat, Jun 11, 2011 at 07:35:26PM +0200, Rieker Flaik wrote:
> I just want to download the first 100 bytes from a URL. What would be
> the best way to do so?
>
> I tried to achieve this with a WriteMemoryCallback
> (CURLOPT_WRITEFUNCTION) but realized that this is just for "where to
> write out the data".

That's the right approach. Presumably, you want to do something with those
first 100 bytes, and that's the function to do it in. Once you've received
all you want, just return 0 from that function and the transfer will
stop. You can also set a CURLOPT_RANGE that will work on certain protocols
with certain servers with certain URLs, but since there's no guarantee it
will work, you'll still need to count bytes in the writefunction.

>>> Dan
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-06-11