问题描述
我有一个mod_rails服务器,磁盘空间,奇怪的是,是一个溢价。有没有办法压缩我的应用程序的来源,如?
I have a mod_rails server where disk space, oddly enough, is at a premium. Is there a way for me to compress my application's source, like Python's zipimport?
这有明显的缺点,所以我应该可以分解并在磁盘空间使用镍,但我认为这是值得一试。
There are obvious disadvantages to this, so I should probably just break down and spend a nickel on disk space, but I figured it'd be worth a shot.
推荐答案
哦,这很整洁。查看宝石:
Oh, this is neat. Check out the rubyzip gem:
(更新 ziprequire.rb不再存在于rubyzip gem中,但链接似乎包含其旧内容。)
(Update: The ziprequire.rb is no longer present in the rubyzip gem, but the source link appears to contain its old content nonetheless.)
这样。这只是稍微修改从他们的例子:
Like so. This is just slightly modified from their example:
require 'rubygems'
require 'zip/zipfilesystem'
require 'zip/ziprequire'
Zip::ZipFile.open("/tmp/mylib.zip", true) do |zip|
zip.file.open('mylib/somefile.rb', 'w') do |file|
file.puts "def foo"
file.puts " puts 'foo was here'"
file.puts "end"
end
end
$:.unshift '/tmp/mylib.zip'
require 'mylib/somefile'
foo # => foo was here
您不必使用rubyzip库来创建压缩库。您可以使用CLI zip。
You don't have to use the rubyzip library to create the zipped library, of course. You can use CLI zip for that.
这篇关于从zip存档加载ruby源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!