zip 파일을 다운로드하고 진행 막대를 표준 출력으로 출력하는 루비 bash 스크립트가 있습니다. 내가 가지고있는 + _ +Ruby가 해시를 Int로 변환 할 수 없습니다.
# 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(file, 'w' ...
기능
에 문제가 있음을 의미
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)
를 얻을 수
내가 같은 일을 물어 막습니다 (영어 설명은 다운로드 파일에 노력하고 있지만 ... 그 경우에
OpenURI::OpenRead#open
방법에'w'
모드를 사용하지 것이라고 말했습니다). Stack trace가 어느 라인에 대해 불평하고 있는가? – nickgroenke라인 191은 열려있는 (파일, 'w', ...) 것입니다 ... 라인 32는'def is_dir (directory)'입니다 – Steven
오 오픈 된 세 번째 인자에 문제가 있는지 궁금합니다. open의 세 번째 인수는 ": content_length_proc => lambda ..."이며 해시입니다. 스택 추적은 open-uri.rb : 32에 대해 이야기합니다. 어쩌면 열린 호출은 세 번째 인수가 Int가 될 것으로 기대하고 있습니다. – nickgroenke