ZIP アーカイブを作成するライブラリを Scheme (Gauche) 用に作って以前に紹介した。
http://saito.hatenablog.jp/entry/2012/10/18/202110
主な用途としては ePub 作成なのだけれど、折角だから普通のアーカイバでは出来ないような何かが出来ないかと考えてこんなコードを書いてみた。
#!/usr/local/bin/gosh (use zip-archive) (call-with-output-zip-archive "test.zip" (lambda(za) (zip-add-entry za "foo.txt" "1") (zip-add-entry za "foo.txt" "2") (zip-add-entry za "foo.txt" "3")))
このコードを走らせると test.zip という ZIP アーカイブが出来る。 そしてそのアーカイブには foo.txt という名前のエントリがみっつあることになる。 同じ名前のエントリがみっつである。 これは問題ないのか?
info-zip でテストすると…。
$ unzip -t test.zip Archive: test.zip testing: foo.txt OK testing: foo.txt OK testing: foo.txt OK No errors detected in compressed data of test.zip.
エラーなし!
念のために別のソフトでもテストしてみよう。 7-zip を使ってテストすると…。
$ 7z t test.zip 7-Zip 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18 Processing archive: test.zip Testing foo.txt Testing foo.txt Testing foo.txt Everything is Ok Files: 3 Size: 3 Compressed: 319
これでもエラーなし!
では展開するとどうなるのか。
$ unzip test.zip Archive: test.zip inflating: foo.txt replace foo.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: y inflating: foo.txt replace foo.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: y inflating: foo.txt $ cat foo.txt 3
最初は普通に展開され、後のふたつについては対処を尋ねられた。 ここでは yes を選択したのでそのまま順序通りに展開され、最後に残ったのは三番目に展開したファイルである。 このあたりの挙動については展開に使うソフトによるだろう。
これが何の役に立つのかはわからない。 有用な使い道を何ひとつ思い付かない。 でも面白い。
Document ID: 5e9f788455470bf6b15f3c77625a812f