# Add files to a gzip file

**URL:** <https://www.ruby-forum.com/t/add-files-to-a-gzip-file/130160>\
**Category:** Rails\
**Created:** [February 25, 2008, 10:13pm UTC](https://www.ruby-forum.com/t/add-files-to-a-gzip-file/130160 "2008-02-25T22:13:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![schnoid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e95f7d/32.png) [@schnoid](https://www.ruby-forum.com/u/schnoid)\
**Post date:** [February 25, 2008, 10:13pm UTC](https://www.ruby-forum.com/t/add-files-to-a-gzip-file/130160/1 "2008-02-25T22:13:01Z")

</div>

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.
