Set the compression level when creating a ZIP file using RubyZip

I have a Ruby program that zips up a directory tree of XML files using rubyzip gem. My problem is that the file starts to be heavy, and I would like to increase the compression level, since the compression time is not a problem.

I could not find in rubyzip documentation a way to specify the compression level for the created ZIP file.

Does anyone know how to change this setting? Is there any other Ruby library that allows you to specify the compression level?

+5
source share
2 answers

, , rubyzip internal.

level = Zlib::BEST_COMPRESSION
Zip::ZipOutputStream.open(zip_file) do |zip|
    Dir.glob("**/*") do |filename|
        entry = Zip::ZipEntry.new("", filename)
        entry.gather_fileinfo_from_srcpath(filename)
        zip.put_next_entry(entry, nil, nil, Zip::ZipEntry::DEFLATED, level)
        entry.get_input_stream { |is| IOExtras.copy_stream(zip, is) }
    end
end
+8

, , , "zip", zipping.

0

All Articles