2009-12-03

Making X binary files of Y bytes

I had to make some dummy files for testing uncompressed zip archives.

Here's what I did:
$ ruby -e 'File::open("hex.bin", "wb") {|f| 1.upto(5*1024) {|b| f.write("\xff")}}'
$ hexdump -Cv hex.bin | tail
00001370  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00001380  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00001390  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
000013a0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
000013b0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
000013c0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
000013d0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
000013e0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
000013f0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00001400
$ ruby -e '1.upto(10) {|i| s = sprintf("%04d",i); `ln -s ./hex.bin ./bin#{s}.bin`}'
$ find . -name "bin*.bin" -print | zip -r -0 -X source -@
$ du -abL
5120    ./bin0007.bin
5120    ./bin0004.bin
52202   ./source.zip
5120    ./bin0006.bin
5120    ./bin0002.bin
5120    ./bin0008.bin
5120    ./bin0005.bin
5120    ./bin0009.bin
5120    ./bin0001.bin
5120    ./hex.bin
5120    ./bin0003.bin
5120    ./bin0010.bin
112618  .
$

Awesome.