如何在 Curb gem 中设置限制利率选项?
我想为 Curb gem(curl 的 ruby 接口)完成的下载设置 --limit-rate
选项。
在curl中:
curl --limit-rate 10K http://server/large_file.rar
对于Curb的下载,我有这个代码(加上进度条,但这与这个问题无关):
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?据我所知,没有简单的方法(我已经阅读了 rdoc 并做了一些谷歌搜索)。
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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过在
libcurl
中设置CURLOPT_MAX_RECV_SPEED_LARGE
来实现此目的。通过curb
API,您可以执行以下操作:其中
download_limit
是最大下载速率(以字节/秒为单位)的整数。有关更多信息: http://curl.haxx.se/libcurl/c/curl_easy_setopt .html#CURLOPTMAXRECVSPEEDLARGE
You would do this by setting
CURLOPT_MAX_RECV_SPEED_LARGE
inlibcurl
. Through thecurb
API, you would do:Where
download_limit
is 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