gpt4 book ai didi

ruby - Zipfile 通过 CURL 下载到文件结构中的实际 Zip 文件

转载 作者:数据小太阳 更新时间:2023-10-29 07:29:24 25 4
gpt4 key购买 nike

我正在尝试使用 RubyGem Curb 构建一个文件下载器。 (查看 This Question 。)

我正在尝试下载一个 zip 文件,然后使用我正在尝试实际制作文件的类文件,以便我可以在 Finder 中双击它(我在 OS X 上)。我将如何将这个“ curl ”的主体转换为 zip 文件。

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

我没有收到任何错误,也找不到任何文件。我已经尝试过绝对路径,没有任何区别。

最佳答案

我正在使用 ruby 2.0

我的代码是:

curl = Curl::Easy.new('http://somepage.cz/index.html')
curl.on_body do |d|
f = File.open('output_file.html', 'w') {|f| f.write(d)}
end
curl.perform

我必须将 File.new 更改为 File.open,否则它不起作用。将 curl.perfom 移到最后确实对我有帮助。

关于ruby - Zipfile 通过 CURL 下载到文件结构中的实际 Zip 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5383143/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com