i have been using rubyzip
for zip/unzip for files/folder ranging from 20MB TO 1GB.i noticed that after zipping a folder of 20MB,the created zipfile is almost of the same size somewhat 20MB.So is rubyzip
just zip the file or actually compresses it because the compressed file must be less than 40%-50% of the actual file size.i even tried using system(zip, archive, Dir["#{path}/**/**"])
but i guess i am unable to get the correct syntax to call it.So my questions are
rubyzip
is unable to create an actual zip file which must be less in size too.rubyzip/zipruby
(which requires libraries too).I am using ruby 1.9 and rails 2.3.
my code:-
require 'zip/zip'
require 'fileutils'
require 'zip/zipfilesystem'
def self.compress_test(path)
path="#{RAILS_ROOT/answers/}"
path.sub!(%r[/$],'')
archive = File.join(path,File.basename(path))+'.zip'
FileUtils.rm archive, :force=>true
Zip::ZipFile.open(archive, 'w') do |zipfile|
Dir["#{path}/**/**"].reject{|f|f==archive}.each do |file|
begin
zipfile.add(file.sub(path+'/',''),file)
rescue Zip::ZipEntryExistsError
end
end
end
end
why rubyzip is unable to create an actual zip file which must be less in size too.
This varies a lot depending on what files you are trying to compress. Text and xls files will compress reasonably well. Media files in formats like JPEG, PNG, MPEG etc are already compressed internally, and often get compression ratios of 99%. They will usually be bigger that other files in the same folder, so the result of compressing a folder with some images, text and spreadsheets will not seem much smaller. Compressing a .zip
file can even make the end result larger than you started.
for a zipfile of more than 500MB,how van i send it to the client using send_file because its going to cost performance issue for a file of that size.what if i place that zip of 500MB or above in public folder and let the server serve it which might improve the performance,am i correct?
Yes, saving a large file to disk, and letting the web server send it may be more efficient. The easiest thing to do would be to save the file to a folder where it can be served from, and provide a link. You could also make that from a different server (e.g. a lighttpd instance dedicated to serving out the large files) to avoid loading your application server.
There are some setups that allow you to pass control back from a Ruby process to e.g. Apache ( xsendfile
is one I know of ), but setting that up would be a different question, it depends what web server you have, and whether you have security concerns.
are there any other option instead of using rubyzip/zipruby(which requires libraries too).
Probably yes, but it is not likely you will find solutions to your two other questions by changing which gem you are using, because rubyzip
is doing a reasonable job here - it is not failing.