Set Compression Level When Generating a Zip File Using Rubyzip

Set compression level when generating a ZIP file using RubyZip

Here is the code I created by looking at 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

JS: Generating a zip file with store level compression

The zip file format is relatively straightforward. You can implement your own zip file creation routines that only produce stored entries. You can find the zip file format documented here.

How can I copy a directory inside a zip archive to a second zip archive using rubyzip?

After checking with one of the maintainers of the rubyzip gem, I have learned that this is not possible.



Related Topics



Leave a reply



Submit