I’d like to set --limit-rate option for downloads done by Curb gem (ruby interface to curl).
In curl:
curl --limit-rate 10K http://server/large_file.rar
For downloads by Curb I have this code (plus progressbar, but that’s not relevant to this question):
require 'rubygems'
require 'curb'
request = 'http://server/large_file.rar'
filename = 'large_file.rar'
f = open(filename, 'wb')
c = Curl::Easy.new(request) do |curl|
curl.on_body { |d| f << d; d.length }
end
c.perform
f.close
How do I set --limit-rate option in this script? As long as I can tell, there’s no easy way (I’ve already read rdoc and done some googling).
You would do this by setting
CURLOPT_MAX_RECV_SPEED_LARGEinlibcurl. Through thecurbAPI, you would do:Where
download_limitis an integer for the maximum download rate in bytes per second.For more info: http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTMAXRECVSPEEDLARGE