Method: Baidu::PCS::Client#download
- Defined in:
- lib/baidu/pcs/client.rb
#download(path, options = {}) ⇒ String #download(path, options = {}) {|segment| ... } ⇒ void
下载单个文件
Download 接口支持 HTTP 协议标准 range 定义,通过指定 range 的取值可以实现断点下载功能。
254 255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/baidu/pcs/client.rb', line 254 def download(path, ={}, &block) site = Baidu::PCS::DOWNLOAD_SITE query = { path: build_path(path) }.update(base_query 'download') headers = if [:begin] || [:end] range = "#{options[:begin] || 0}-#{options[:end]}" { Range: "bytes=#{range}" } end if block_given? get "#{BASE_PATH}/file", query, site: site, headers: headers, &block else get "#{BASE_PATH}/file", query, site: site, headers: headers, raw: true end end |