splitbrain/dokuwiki — pull request #162 by glensc (2013-01-23 12:01:07+00:00)
Title: handle bz (bzip not bzip2) better

in fact .tbz is tar.bz (bzip1) and .tbz2 is what tar.bz2 is used
commonly.

i modified the code, but did not run any tests (not automated unittests or uploads with the ui), haven't figured out yet how to run them

anyway, seems the two bytes of both compressor match signature used in dokuwiki and php-bz2 extension opens the stream without errors:

$ tar -cf /tmp/a.tar.bz --use-compress=bzip .gitignore
$ tar -cf /tmp/a.tar.bz2 --use-compress=bzip2 .gitignore

$ file /tmp/a.tar.bz*
/tmp/a.tar.bz: data
/tmp/a.tar.bz2: bzip2 compressed data, block size = 900k

$ cut -c1-4 /tmp/a.tar.bz | od -cx
0000000 B Z 0 9 \n ` \0 \n
5a42 3930 600a 0a00
0000010
$ cut -c1-4 /tmp/a.tar.bz2 | od -cx
0000000 B Z h 9 \n \t % 032 017 \n J \f 311 206 \n X
5a42 3968 090a 1a25 0a0f 0c4a 86c9 580a
0000020 > j * \n 367 w m 031 \n
6a3e 0a2a 77f7 196d 000a
0000031

$ php -r '$f=bzopen("/tmp/a.tar.bz", "r"); var_dump($f);'|less
resource(4) of type (stream)
$ php -r '$f=bzopen("/tmp/a.tar.bz2", "r"); var_dump($f);'|less
resource(4) of type (stream)