From: Brian Candler Date: 2010-06-08T17:11:05+09:00 Subject: Re: Rubyzip - `dup': can't dup NilClass (TypeError) Luka Stolyarov wrote: > require 'rubygems' > require 'zip/zip' > > zf = Zip::ZipFile.open('616910.zip') > > However, when I run it, it throws an error > > /Users/lukastolyarov/.gem/ruby/1.8/gems/rubyzip-0.9.4/lib/zip/zip.rb:1163:in > `dup': can't dup NilClass (TypeError) Works fine for me with rubyzip-0.9.1 + "ruby 1.8.6 (2007-09-24 patchlevel 111) [i486-linux]", and I just upgraded to rubyzip-0.9.4 with the same results. What platform are you on? The offending code is here: # deep clone def dup newZipEntrySet = ZipEntrySet.new(@entrySet.values.map { |e| e.dup }) end which suggests to me that the zipfile is corrupt or an unsupported format, since @entrySet must contain a {value=>nil} pair. Try modifying this code (line 657): def ZipEntry.read_c_dir_entry(io) #:nodoc:all entry = new(io.path) entry.read_c_dir_entry(io) return entry rescue ZipError return nil end For example, comment out the rescue ZipError // return nil pair. It seems that this error handling is bad. Either an exception should be raised here, or the bad entry should be skipped (not saved as a nil value in @entrySet which causes the dup error you saw) Regards, Brian. -- Posted via http://www.ruby-forum.com/.