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?
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.
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).
Gzip is not a container format.
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.
On Thu, 2008-03-20 at 22:24 +0100, Jaime I. wrote:
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).
Another issue to keep in mind, is if the operation takes a long time
to finish(over 60 seconds), the browser may timeout. So you might want
to do an ajax callback to check if the file is ready for download
instead of having the GET response on the browser waiting.