tags:

views:

8

answers:

1

i'm trying to get some number of bytes from source using libcurl by setting:

curl_easy_setopt(curl, CURLOPT_BUFFERSIZE, 100); //get 100 bytes from source

But I get different size of data each time, not even close sometimes only 22 bytes. does this work?

A: 

From the documentation:

Pass a long specifying your preferred size (in bytes) for the receive buffer in libcurl. The main point of this would be that the write callback gets called more often and with smaller chunks. This is just treated as a request, not an order. You cannot be guaranteed to actually get the given size. (Added in 7.10)

This size is by default set as big as possible (CURL_MAX_WRITE_SIZE), so it only makes sense to use this option if you want it smaller.you want it smaller.

So there isn't really any easy way to get 100 bytes right away. You would need to keep track of how many bytes you have received and just stop reading once you've got 100.

thelsdj