1
我有以下Ruby代碼:紅寶石解壓 - 失敗,未初始化的不斷ZIP ::下載
require 'HTTPClient'
require 'rubygems'
require 'zip'
def self.unzip(data, dest_dir)
::Zip::File.open_buffer(data) do |fzip|
fzip.each do |entry|
path = File.join(dest_dir, entry.name)
puts "here"
FileUtils::mkdir_p(File.dirname(path))
fzip.extract(entry, path) unless File.exist?(path)
#fzip.close
end
end
end
def self.fetch_from_url(url, dest_dir)
response = HTTPClient.get(url, follows_redirect: true)
if response.status == 200
unzip(response.body, dest_dir)
else
raise 'Could not fetch files from 3scale'
end
end
url = 'link/artifactory/zip-release-local/djin/3Sroxy/1.0.5/configuration.zip'
fetch_from_url(url, "/Users/something/")
當我在Mac紅寶石2.0.0p481它工作正常,並解壓的文件夾,但運行這個當我運行在CentOS的6.6紅寶石1.8.7它同樣失敗,以下內容:
[[email protected] ~]# sudo ruby test/ex.rb
test/ex.rb:7:in `unzip': uninitialized constant Zip::File (NameError)
from test/ex.rb:20:in `fetch_from_url'
from test/ex.rb:28
還,我做:
gem install zip
Successfully installed zip-2.0.2
1 gem installed
Installing ri documentation for zip-2.0.2...
Installing RDoc documentation for zip-2.0.2...
您是否完成了捆綁安裝? –
@Alif Jamaluddin - 我已經完成了[root @ ip-10-201-90-206〜]#gem install zip 已成功安裝zip-2.0.2 已安裝1個gem 爲zip-2.0.2安裝ri文檔。 .. 安裝zip-2.0.2的RDoc文檔... – Scooby
您需要使用'rubyzip' gem @Scooby – Prashant4224