わたなべです.

zip file の中身の list を表示する script です.
使いかたは ziplist.rb foo.zip bar.zip のように複数の zip
file を指定できます(ここがオリジナルと違う).
ちなみに展開はしません.

ところで VERSION < "1.1b7" のような check を入れてみたんだけ
ど, 正式に 1.1 が出た場合これはどうなるのかな?
"1.1" < "1.1b7" は真だからまずい気もする.

-- 
わたなべひろふみ

#!/usr/local/bin/ruby # usage: ziplist.rb foo.zip raise "ruby 1.1b7 required" if VERSION < "1.1b7" if ARGV.size == 0 puts "usage: #$0 files ..." exit 1 end def dostime time format "%04d-%02d-%02d %02d:%02d:%02d", (time >> 16+9 & 0x7f) + 1980, time >> 16+5 & 0x0f, time >> 16 & 0x1f, time >> 11 & 0x1f, time >> 5 & 0x3f, (time & 0x1f) * 2 end for zipfile in ARGV zip = open(zipfile, "rb") puts "Archive: #{zipfile}" puts " Length Date Time Name" puts " ------ ---- ---- ----" while (header = zip.read(30)).size > 0 break unless header.unpack('V')[0] == 0x04034b50 size = header.unpack('x18Vx4vv') zip.seek size[0] + size[1] + size[2], 1 end zip.seek -30, 1 count = 0 total = 0 while (header = zip.read(4)).size > 0 break unless header.unpack('V')[0] == 0x02014b50 break unless (header = zip.read(42)).size == 42 nlen, elen, elen2 = header.unpack('x24v3') elen += elen2 break if 256 < nlen break unless (name = zip.read(nlen)).size == nlen time, size = header.unpack('x8Vx8V') printf "%8d %s %s\n", size, dostime(time), name zip.seek elen, 1 count += 1 total += size end zip.close puts " ------- -------" printf "%8d %d files\n\n", total, count end exit 0