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
- why
rubyzip
is unable to create an actual zip file which must be less in size too. - 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?
- are there any other option instead of using
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
xls
files should compress a little (maybe to 50% of original), butjpg
,png
orgif
will not (they are already compressed inside, you'll get 99% original size or similar) - the images are usually larger files than the spreadsheets, so you probably won't notice in the total file size. – Neil Slater