我有一个 ruby bash 脚本来下载 zip 文件并将进度条输出到标准输出。我有以下
# Temp file name
tmp = ActiveSupport::SecureRandom.hex(8)
file = temp_dl_dir+tmp+'.zip'
print file.inspect
# Download
progress_bar = nil
open(file, 'w', :content_length_proc => lambda { |length|
if length && 0 < length
progress_bar = ProgressBar.new('...', length)
progress_bar.file_transfer_mode
end
},
:progress_proc => lambda { |progress|
progress_bar.set(progress) if progress_bar
}) do |fo|
fo.print open(dl).read
end
但是当我运行它时,我得到
open-uri.rb:32:in `initialize': can't convert Hash into Integer (TypeError)
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/open-uri.rb:32:in `open_uri_original_open'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/open-uri.rb:32:in `open'
from ./site.rb:191 (line 191 is the open(file, 'w' ...) one)
open(file, 'w' ...
这意味着我的功能有问题
我不知道怎么了 +_+