Add files to a gzip file

I'd like to add several separate files into a new Gzip file created within ruby.

The code I've got at the moment is as follows:

File.open('coursework_submissions.gz', 'wb') do |f| gz = Zlib::GzipWriter.new(f) @student_list.each do |s|   temp = File.open("#{s.student.student_no}", 'wb')   temp.write(s.submission)   temp.close()   gz.add(File.open("#{s.student.student_no}", 'r'))   File.delete("#{s.student.student_no}") end gz.close end

However, this just produces a file, coursework_submissions.gz, containing a file, coursework_submissions with the text of the files I want to add contained inside. Where am I going wrong?

Thanks everyone.

Hi, I also need to compress a folder containing several jpg files to a .zip file. I don't want to generate a .tar.gz file, but a .zip file that standard windows users can open (I'm an Ubuntu user but my client is not).

How can I do that?

Use rubyzip (http://rubyzip.sourceforge.net/)) or the command line version of zip (install it if needed using “sudo apt-get install zip”). Google around for some examples on rubyzip. Although I personally would prefer the command line calls.

Best regards

Peter De Berdt

> > Martyn Jones wrote: > > > However, this just produces a file, coursework_submissions.gz, > > containing a file, coursework_submissions with the text of the files I > > want to add contained inside. Where am I going wrong? > > Gzip is not a container format. > > Usually one use TAR to pack multiple files/objects into one archive and > than gzip it.

Hi, I also need to compress a folder containing several jpg files to a .zip file. I don't want to generate a .tar.gz file, but a .zip file that standard windows users can open (I'm an Ubuntu user but my client is not).

How can I do that?