On 8/15/05, len <lsumnler / gmail.com> wrote:
> Hello all.
> 
> I am running Ruby 1.8.2 on XP professional.  Have installed RubyZip
> through gems.
> 
> I have tried to create a zip file containing all of the .dat file in a
> particular directory.  It appears that I only get the last .dat file
> ziped.  Can anyone point me in the right direction.  Please remember I
> have just started to learn Ruby but am trying to create some small but
> usefull functions.  I looked through the news group for similar post
> and tried googling for additional documentation on the RubyZip and seem
> to have come up short.

Well, I was just going to bang this one out, and help you out, but
rubyzip is pretty odd.
It's the most Java-like Ruby program I have seen.  Looking at the docs
and the source code, I've just written a number of test programs,
starting with this:

require 'rubygems'
require 'zip/zip'
Zip::ZipFile.open('example.zip',Zip::ZipFile::CREATE) do |zfile|
  Dir["*.dat"].each do |file_name|
  	zfile.add(file_name, file_name)
  end
end

However, that gives me:
c:/ruby/lib/ruby/1.8/delegate.rb:105:in `method_missing': undefined
method `copy_stream' for #<Zip::ZipStreamableFile:0x2cbdeb8>
(NoMethodError)
        from c:/ruby/lib/ruby/gems/1.8/gems/rubyzip-0.5.9/lib/zip/zip.rb:1282:in
`write_to_zip_output_stream'

copy_stream comes from "fileutils.rb", and I get that error even if I
include it and edit the rubyzip source to make an explicit call to it.

So.. Blocked by that, I found another mailing list posting which got
me headed in the right direction.. This now works for me. (Note the
'b' as part of the file mode. Nothing worked until I set it to binary
mode, at least on Windows XP)

require 'zip/zip'
Zip::ZipOutputStream.open("example.zip") do |zos|
  Dir["*.dat"].each do |file_name|
  	zos.put_next_entry(file_name)
  	File.open(file_name,'rb') do |f|
	  zos.write(f.read)
	end
  end
end

Short answer: Someone needs to point out another zip library for Ruby. Heh.