bzip2.txt 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. NAME
  2. bzip2, bunzip2 - a block-sorting file compressor, v1.0.6
  3. bzcat - decompresses files to stdout
  4. bzip2recover - recovers data from damaged bzip2 files
  5. SYNOPSIS
  6. bzip2 [ -cdfkqstvzVL123456789 ] [ filenames ... ]
  7. bunzip2 [ -fkvsVL ] [ filenames ... ]
  8. bzcat [ -s ] [ filenames ... ]
  9. bzip2recover filename
  10. DESCRIPTION
  11. bzip2 compresses files using the Burrows-Wheeler block
  12. sorting text compression algorithm, and Huffman coding.
  13. Compression is generally considerably better than that
  14. achieved by more conventional LZ77/LZ78-based compressors,
  15. and approaches the performance of the PPM family of sta-
  16. tistical compressors.
  17. The command-line options are deliberately very similar to
  18. those of GNU gzip, but they are not identical.
  19. bzip2 expects a list of file names to accompany the com-
  20. mand-line flags. Each file is replaced by a compressed
  21. version of itself, with the name "original_name.bz2".
  22. Each compressed file has the same modification date, per-
  23. missions, and, when possible, ownership as the correspond-
  24. ing original, so that these properties can be correctly
  25. restored at decompression time. File name handling is
  26. naive in the sense that there is no mechanism for preserv-
  27. ing original file names, permissions, ownerships or dates
  28. in filesystems which lack these concepts, or have serious
  29. file name length restrictions, such as MS-DOS.
  30. bzip2 and bunzip2 will by default not overwrite existing
  31. files. If you want this to happen, specify the -f flag.
  32. If no file names are specified, bzip2 compresses from
  33. standard input to standard output. In this case, bzip2
  34. will decline to write compressed output to a terminal, as
  35. this would be entirely incomprehensible and therefore
  36. pointless.
  37. bunzip2 (or bzip2 -d) decompresses all specified files.
  38. Files which were not created by bzip2 will be detected and
  39. ignored, and a warning issued. bzip2 attempts to guess
  40. the filename for the decompressed file from that of the
  41. compressed file as follows:
  42. filename.bz2 becomes filename
  43. filename.bz becomes filename
  44. filename.tbz2 becomes filename.tar
  45. filename.tbz becomes filename.tar
  46. anyothername becomes anyothername.out
  47. If the file does not end in one of the recognised endings,
  48. .bz2, .bz, .tbz2 or .tbz, bzip2 complains that it cannot
  49. guess the name of the original file, and uses the original
  50. name with .out appended.
  51. As with compression, supplying no filenames causes decom-
  52. pression from standard input to standard output.
  53. bunzip2 will correctly decompress a file which is the con-
  54. catenation of two or more compressed files. The result is
  55. the concatenation of the corresponding uncompressed files.
  56. Integrity testing (-t) of concatenated compressed files is
  57. also supported.
  58. You can also compress or decompress files to the standard
  59. output by giving the -c flag. Multiple files may be com-
  60. pressed and decompressed like this. The resulting outputs
  61. are fed sequentially to stdout. Compression of multiple
  62. files in this manner generates a stream containing multi-
  63. ple compressed file representations. Such a stream can be
  64. decompressed correctly only by bzip2 version 0.9.0 or
  65. later. Earlier versions of bzip2 will stop after decom-
  66. pressing the first file in the stream.
  67. bzcat (or bzip2 -dc) decompresses all specified files to
  68. the standard output.
  69. bzip2 will read arguments from the environment variables
  70. BZIP2 and BZIP, in that order, and will process them
  71. before any arguments read from the command line. This
  72. gives a convenient way to supply default arguments.
  73. Compression is always performed, even if the compressed
  74. file is slightly larger than the original. Files of less
  75. than about one hundred bytes tend to get larger, since the
  76. compression mechanism has a constant overhead in the
  77. region of 50 bytes. Random data (including the output of
  78. most file compressors) is coded at about 8.05 bits per
  79. byte, giving an expansion of around 0.5%.
  80. As a self-check for your protection, bzip2 uses 32-bit
  81. CRCs to make sure that the decompressed version of a file
  82. is identical to the original. This guards against corrup-
  83. tion of the compressed data, and against undetected bugs
  84. in bzip2 (hopefully very unlikely). The chances of data
  85. corruption going undetected is microscopic, about one
  86. chance in four billion for each file processed. Be aware,
  87. though, that the check occurs upon decompression, so it
  88. can only tell you that something is wrong. It can't help
  89. you recover the original uncompressed data. You can use
  90. bzip2recover to try to recover data from damaged files.
  91. Return values: 0 for a normal exit, 1 for environmental
  92. problems (file not found, invalid flags, I/O errors, &c),
  93. 2 to indicate a corrupt compressed file, 3 for an internal
  94. consistency error (eg, bug) which caused bzip2 to panic.
  95. OPTIONS
  96. -c --stdout
  97. Compress or decompress to standard output.
  98. -d --decompress
  99. Force decompression. bzip2, bunzip2 and bzcat are
  100. really the same program, and the decision about
  101. what actions to take is done on the basis of which
  102. name is used. This flag overrides that mechanism,
  103. and forces bzip2 to decompress.
  104. -z --compress
  105. The complement to -d: forces compression,
  106. regardless of the invocation name.
  107. -t --test
  108. Check integrity of the specified file(s), but don't
  109. decompress them. This really performs a trial
  110. decompression and throws away the result.
  111. -f --force
  112. Force overwrite of output files. Normally, bzip2
  113. will not overwrite existing output files. Also
  114. forces bzip2 to break hard links to files, which it
  115. otherwise wouldn't do.
  116. bzip2 normally declines to decompress files which
  117. don't have the correct magic header bytes. If
  118. forced (-f), however, it will pass such files
  119. through unmodified. This is how GNU gzip behaves.
  120. -k --keep
  121. Keep (don't delete) input files during compression
  122. or decompression.
  123. -s --small
  124. Reduce memory usage, for compression, decompression
  125. and testing. Files are decompressed and tested
  126. using a modified algorithm which only requires 2.5
  127. bytes per block byte. This means any file can be
  128. decompressed in 2300k of memory, albeit at about
  129. half the normal speed.
  130. During compression, -s selects a block size of
  131. 200k, which limits memory use to around the same
  132. figure, at the expense of your compression ratio.
  133. In short, if your machine is low on memory (8
  134. megabytes or less), use -s for everything. See
  135. MEMORY MANAGEMENT below.
  136. -q --quiet
  137. Suppress non-essential warning messages. Messages
  138. pertaining to I/O errors and other critical events
  139. will not be suppressed.
  140. -v --verbose
  141. Verbose mode -- show the compression ratio for each
  142. file processed. Further -v's increase the ver-
  143. bosity level, spewing out lots of information which
  144. is primarily of interest for diagnostic purposes.
  145. -L --license -V --version
  146. Display the software version, license terms and
  147. conditions.
  148. -1 (or --fast) to -9 (or --best)
  149. Set the block size to 100 k, 200 k .. 900 k when
  150. compressing. Has no effect when decompressing.
  151. See MEMORY MANAGEMENT below. The --fast and --best
  152. aliases are primarily for GNU gzip compatibility.
  153. In particular, --fast doesn't make things signifi-
  154. cantly faster. And --best merely selects the
  155. default behaviour.
  156. -- Treats all subsequent arguments as file names, even
  157. if they start with a dash. This is so you can han-
  158. dle files with names beginning with a dash, for
  159. example: bzip2 -- -myfilename.
  160. --repetitive-fast --repetitive-best
  161. These flags are redundant in versions 0.9.5 and
  162. above. They provided some coarse control over the
  163. behaviour of the sorting algorithm in earlier ver-
  164. sions, which was sometimes useful. 0.9.5 and above
  165. have an improved algorithm which renders these
  166. flags irrelevant.
  167. MEMORY MANAGEMENT
  168. bzip2 compresses large files in blocks. The block size
  169. affects both the compression ratio achieved, and the
  170. amount of memory needed for compression and decompression.
  171. The flags -1 through -9 specify the block size to be
  172. 100,000 bytes through 900,000 bytes (the default) respec-
  173. tively. At decompression time, the block size used for
  174. compression is read from the header of the compressed
  175. file, and bunzip2 then allocates itself just enough memory
  176. to decompress the file. Since block sizes are stored in
  177. compressed files, it follows that the flags -1 to -9 are
  178. irrelevant to and so ignored during decompression.
  179. Compression and decompression requirements, in bytes, can
  180. be estimated as:
  181. Compression: 400k + ( 8 x block size )
  182. Decompression: 100k + ( 4 x block size ), or
  183. 100k + ( 2.5 x block size )
  184. Larger block sizes give rapidly diminishing marginal
  185. returns. Most of the compression comes from the first two
  186. or three hundred k of block size, a fact worth bearing in
  187. mind when using bzip2 on small machines. It is also
  188. important to appreciate that the decompression memory
  189. requirement is set at compression time by the choice of
  190. block size.
  191. For files compressed with the default 900k block size,
  192. bunzip2 will require about 3700 kbytes to decompress. To
  193. support decompression of any file on a 4 megabyte machine,
  194. bunzip2 has an option to decompress using approximately
  195. half this amount of memory, about 2300 kbytes. Decompres-
  196. sion speed is also halved, so you should use this option
  197. only where necessary. The relevant flag is -s.
  198. In general, try and use the largest block size memory con-
  199. straints allow, since that maximises the compression
  200. achieved. Compression and decompression speed are virtu-
  201. ally unaffected by block size.
  202. Another significant point applies to files which fit in a
  203. single block -- that means most files you'd encounter
  204. using a large block size. The amount of real memory
  205. touched is proportional to the size of the file, since the
  206. file is smaller than a block. For example, compressing a
  207. file 20,000 bytes long with the flag -9 will cause the
  208. compressor to allocate around 7600k of memory, but only
  209. touch 400k + 20000 * 8 = 560 kbytes of it. Similarly, the
  210. decompressor will allocate 3700k but only touch 100k +
  211. 20000 * 4 = 180 kbytes.
  212. Here is a table which summarises the maximum memory usage
  213. for different block sizes. Also recorded is the total
  214. compressed size for 14 files of the Calgary Text Compres-
  215. sion Corpus totalling 3,141,622 bytes. This column gives
  216. some feel for how compression varies with block size.
  217. These figures tend to understate the advantage of larger
  218. block sizes for larger files, since the Corpus is domi-
  219. nated by smaller files.
  220. Compress Decompress Decompress Corpus
  221. Flag usage usage -s usage Size
  222. -1 1200k 500k 350k 914704
  223. -2 2000k 900k 600k 877703
  224. -3 2800k 1300k 850k 860338
  225. -4 3600k 1700k 1100k 846899
  226. -5 4400k 2100k 1350k 845160
  227. -6 5200k 2500k 1600k 838626
  228. -7 6100k 2900k 1850k 834096
  229. -8 6800k 3300k 2100k 828642
  230. -9 7600k 3700k 2350k 828642
  231. RECOVERING DATA FROM DAMAGED FILES
  232. bzip2 compresses files in blocks, usually 900kbytes long.
  233. Each block is handled independently. If a media or trans-
  234. mission error causes a multi-block .bz2 file to become
  235. damaged, it may be possible to recover data from the
  236. undamaged blocks in the file.
  237. The compressed representation of each block is delimited
  238. by a 48-bit pattern, which makes it possible to find the
  239. block boundaries with reasonable certainty. Each block
  240. also carries its own 32-bit CRC, so damaged blocks can be
  241. distinguished from undamaged ones.
  242. bzip2recover is a simple program whose purpose is to
  243. search for blocks in .bz2 files, and write each block out
  244. into its own .bz2 file. You can then use bzip2 -t to test
  245. the integrity of the resulting files, and decompress those
  246. which are undamaged.
  247. bzip2recover takes a single argument, the name of the dam-
  248. aged file, and writes a number of files
  249. "rec00001file.bz2", "rec00002file.bz2", etc, containing
  250. the extracted blocks. The output filenames are
  251. designed so that the use of wildcards in subsequent pro-
  252. cessing -- for example, "bzip2 -dc rec*file.bz2 > recov-
  253. ered_data" -- processes the files in the correct order.
  254. bzip2recover should be of most use dealing with large .bz2
  255. files, as these will contain many blocks. It is clearly
  256. futile to use it on damaged single-block files, since a
  257. damaged block cannot be recovered. If you wish to min-
  258. imise any potential data loss through media or transmis-
  259. sion errors, you might consider compressing with a smaller
  260. block size.
  261. PERFORMANCE NOTES
  262. The sorting phase of compression gathers together similar
  263. strings in the file. Because of this, files containing
  264. very long runs of repeated symbols, like "aabaabaabaab
  265. ..." (repeated several hundred times) may compress more
  266. slowly than normal. Versions 0.9.5 and above fare much
  267. better than previous versions in this respect. The ratio
  268. between worst-case and average-case compression time is in
  269. the region of 10:1. For previous versions, this figure
  270. was more like 100:1. You can use the -vvvv option to mon-
  271. itor progress in great detail, if you want.
  272. Decompression speed is unaffected by these phenomena.
  273. bzip2 usually allocates several megabytes of memory to
  274. operate in, and then charges all over it in a fairly ran-
  275. dom fashion. This means that performance, both for com-
  276. pressing and decompressing, is largely determined by the
  277. speed at which your machine can service cache misses.
  278. Because of this, small changes to the code to reduce the
  279. miss rate have been observed to give disproportionately
  280. large performance improvements. I imagine bzip2 will per-
  281. form best on machines with very large caches.
  282. CAVEATS
  283. I/O error messages are not as helpful as they could be.
  284. bzip2 tries hard to detect I/O errors and exit cleanly,
  285. but the details of what the problem is sometimes seem
  286. rather misleading.
  287. This manual page pertains to version 1.0.6 of bzip2. Com-
  288. pressed data created by this version is entirely forwards
  289. and backwards compatible with the previous public
  290. releases, versions 0.1pl2, 0.9.0, 0.9.5, 1.0.0, 1.0.1,
  291. 1.0.2 and above, but with the following exception: 0.9.0
  292. and above can correctly decompress multiple concatenated
  293. compressed files. 0.1pl2 cannot do this; it will stop
  294. after decompressing just the first file in the stream.
  295. bzip2recover versions prior to 1.0.2 used 32-bit integers
  296. to represent bit positions in compressed files, so they
  297. could not handle compressed files more than 512 megabytes
  298. long. Versions 1.0.2 and above use 64-bit ints on some
  299. platforms which support them (GNU supported targets, and
  300. Windows). To establish whether or not bzip2recover was
  301. built with such a limitation, run it without arguments.
  302. In any event you can build yourself an unlimited version
  303. if you can recompile it with MaybeUInt64 set to be an
  304. unsigned 64-bit integer.
  305. AUTHOR
  306. Julian Seward, jsewardbzip.org.
  307. http://www.bzip.org
  308. The ideas embodied in bzip2 are due to (at least) the fol-
  309. lowing people: Michael Burrows and David Wheeler (for the
  310. block sorting transformation), David Wheeler (again, for
  311. the Huffman coder), Peter Fenwick (for the structured cod-
  312. ing model in the original bzip, and many refinements), and
  313. Alistair Moffat, Radford Neal and Ian Witten (for the
  314. arithmetic coder in the original bzip). I am much
  315. indebted for their help, support and advice. See the man-
  316. ual in the source distribution for pointers to sources of
  317. documentation. Christian von Roques encouraged me to look
  318. for faster sorting algorithms, so as to speed up compres-
  319. sion. Bela Lubkin encouraged me to improve the worst-case
  320. compression performance. Donna Robinson XMLised the docu-
  321. mentation. The bz* scripts are derived from those of GNU
  322. gzip. Many people sent patches, helped with portability
  323. problems, lent machines, gave advice and were generally
  324. helpful.