From: Thomas Sondergaard Date: 2005-09-04T23:41:28+09:00 Subject: Re: Zip Extraction Bug? ded wrote: > 1. "rake test" fails on my system because it assumes that each > directory has a .cvsignore file (which are not part of the > distribution). After doing a "touch .cvsignore" in each of the > installation directories, the problem went away. Okay, I'll take a look at that. Thanks > 2. I used Zip::ZipFile.each to enumerate the entries in the archive, > but in reading the documentation it looks like "foreach" is the > iterator. When I tried that, I got an error saying there was no such > method for the Zip::ZipFile class. There is an "each" but that does > not appear in the documentation. foreach is a class method, so it is used like this Zip::ZipFile.foreach("my.zip") { |zf| ... } Zip::ZipFile#each is inherited from Zip::ZipCentralDirectory. You have to pay attention to notice that ZipFile is a descendant of ZipCentralDirectory, maybe an adjustment of the rdoc stylesheet use for http://rubyzip.sf.net can fix that. > 3. I would have found it really helpful to see an example of iterating > through a zip archive and extracting all the entries. The > documentation appears to lack one for this very common unzip operation. Noted. > 4. A design issue. I would have thought it natural for "extract" to > default the second argument to "./entry.name" so that in the most > common case, it would not need to be supplied. Also noted. > 5. Another design issue. It would seem more natural to me to make > "extract" a method of the Zip::ZipEntry class, which would defult to > extracting itself into the current directory with the entry name. That > way, an unzip operation would become: > > Zip::ZipFile.open("archive.zip").each { |entry| > entry.extract > } > Extraction now requires an awkward reference to the Zip::ZipFile object > inside the block. > Good idea. > 6. The extract method should have a parameter that specifies whether > over-writing an existing file should occur. In my opinion, it should > default to overwriting, but I'll concede that that may be the wrong > choice. It already has. ZipFile#extract accepts a block. If the block returns true the destination is overwritten. See ziptest.rb:1403. Thomas