Zipfile通过CURL下载到您的文件结构中的实际Zip文件 [英] Zipfile download through CURL to an actual Zip-file in your file structure

查看:200
本文介绍了Zipfile通过CURL下载到您的文件结构中的实际Zip文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用RubyGem Curb构建一个文件下载器。 (请参阅此问题。)

I am trying to build a file downloader with the RubyGem Curb. (Look at This Question.)

我试图下载一个zip文件,然后与类文件我试图实际使文件,以便我可以双击它在Finder(我在OS X上)。我将如何将这个Curl'ed体转换为zip文件。

I am trying to download a zip file and then with the class File I am trying to actually make the file so that I can double click it in Finder (I am on OS X). How would I go about to convert this "Curl'ed" body to a zip-file.

require 'rubygems'
require 'curb'

class Download
  def start
    curl = Curl::Easy.new('http://wordpress.org/latest.zip')
    curl.perform
    curl.on_body {
      |d| f = File.new('test.zip', 'w') {|f| f.write d}
    }
  end
end

dl = Download.new
dl.start

我没有得到任何错误,也找不到任何文件。

I am not getting any error, neither can I find any file. I have tried absolute paths with no difference.

推荐答案

您正在添加 on_body 事件调用后执行,这会传输正文。如果将事件声明移动到执行调用之前,这应该可以工作。

You're adding the on_body event after calling perform, which transfers the body. If you move the event declaration to before the perform call, this should work.

这篇关于Zipfile通过CURL下载到您的文件结构中的实际Zip文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆