⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 manual.texi

📁 bzip2是一个免费的
💻 TEXI
📖 第 1 页 / 共 5 页
字号:
compression and decompression.  The flags @code{-1} through @code{-9}specify the block size to be 100,000 bytes through 900,000 bytes (thedefault) respectively.  At decompression time, the block size used forcompression is read from the header of the compressed file, and@code{bunzip2} then allocates itself just enough memory to decompressthe file.  Since block sizes are stored in compressed files, it followsthat the flags @code{-1} to @code{-9} are irrelevant to and so ignoredduring decompression.Compression and decompression requirements, in bytes, can be estimatedas:@example     Compression:   400k + ( 8 x block size )     Decompression: 100k + ( 4 x block size ), or                    100k + ( 2.5 x block size )@end exampleLarger block sizes give rapidly diminishing marginal returns.  Most ofthe compression comes from the first two or three hundred k of blocksize, a fact worth bearing in mind when using @code{bzip2} on small machines.It is also important to appreciate that the decompression memoryrequirement is set at compression time by the choice of block size.For files compressed with the default 900k block size, @code{bunzip2}will require about 3700 kbytes to decompress.  To support decompressionof any file on a 4 megabyte machine, @code{bunzip2} has an option todecompress using approximately half this amount of memory, about 2300kbytes.  Decompression speed is also halved, so you should use thisoption only where necessary.  The relevant flag is @code{-s}.In general, try and use the largest block size memory constraints allow,since that maximises the compression achieved.  Compression anddecompression speed are virtually unaffected by block size.Another significant point applies to files which fit in a single block-- that means most files you'd encounter using a large block size.  Theamount of real memory touched is proportional to the size of the file,since the file is smaller than a block.  For example, compressing a file20,000 bytes long with the flag @code{-9} will cause the compressor toallocate around 7600k of memory, but only touch 400k + 20000 * 8 = 560kbytes of it.  Similarly, the decompressor will allocate 3700k but onlytouch 100k + 20000 * 4 = 180 kbytes.Here is a table which summarises the maximum memory usage for differentblock sizes.  Also recorded is the total compressed size for 14 files ofthe Calgary Text Compression Corpus totalling 3,141,622 bytes.  Thiscolumn gives some feel for how compression varies with block size.These figures tend to understate the advantage of larger block sizes forlarger files, since the Corpus is dominated by smaller files.@example          Compress   Decompress   Decompress   Corpus   Flag     usage      usage       -s usage     Size    -1      1200k       500k         350k      914704    -2      2000k       900k         600k      877703    -3      2800k      1300k         850k      860338    -4      3600k      1700k        1100k      846899    -5      4400k      2100k        1350k      845160    -6      5200k      2500k        1600k      838626    -7      6100k      2900k        1850k      834096    -8      6800k      3300k        2100k      828642    -9      7600k      3700k        2350k      828642@end example@unnumberedsubsubsec RECOVERING DATA FROM DAMAGED FILES@code{bzip2} compresses files in blocks, usually 900kbytes long.  Eachblock is handled independently.  If a media or transmission error causesa multi-block @code{.bz2} file to become damaged, it may be possible torecover data from the undamaged blocks in the file.The compressed representation of each block is delimited by a 48-bitpattern, which makes it possible to find the block boundaries withreasonable certainty.  Each block also carries its own 32-bit CRC, sodamaged blocks can be distinguished from undamaged ones.@code{bzip2recover} is a simple program whose purpose is to search forblocks in @code{.bz2} files, and write each block out into its own@code{.bz2} file.  You can then use @code{bzip2 -t} to test theintegrity of the resulting files, and decompress those which areundamaged.@code{bzip2recover} takes a single argument, the name of the damaged file, and writes anumber of files @code{rec00001file.bz2}, @code{rec00002file.bz2}, etc,containing the extracted blocks.  The output filenames are designed sothat the use of wildcards in subsequent processing -- for example,@code{bzip2 -dc rec*file.bz2 > recovered_data} -- processes the files inthe correct order.@code{bzip2recover} should be of most use dealing with large @code{.bz2}files, as these will contain many blocks.  It is clearly futile to useit on damaged single-block files, since a damaged block cannot berecovered.  If you wish to minimise any potential data loss throughmedia or transmission errors, you might consider compressing with asmaller block size.@unnumberedsubsubsec PERFORMANCE NOTESThe sorting phase of compression gathers together similar strings in thefile.  Because of this, files containing very long runs of repeatedsymbols, like "aabaabaabaab ..."  (repeated several hundred times) maycompress more slowly than normal.  Versions 0.9.5 and above fare muchbetter than previous versions in this respect.  The ratio betweenworst-case and average-case compression time is in the region of 10:1.For previous versions, this figure was more like 100:1.  You can use the@code{-vvvv} option to monitor progress in great detail, if you want.Decompression speed is unaffected by these phenomena.@code{bzip2} usually allocates several megabytes of memory to operatein, and then charges all over it in a fairly random fashion.  This meansthat performance, both for compressing and decompressing, is largelydetermined by the speed at which your machine can service cache misses.Because of this, small changes to the code to reduce the miss rate havebeen observed to give disproportionately large performance improvements.I imagine @code{bzip2} will perform best on machines with very largecaches.@unnumberedsubsubsec CAVEATSI/O error messages are not as helpful as they could be.  @code{bzip2}tries hard to detect I/O errors and exit cleanly, but the details ofwhat the problem is sometimes seem rather misleading.This manual page pertains to version 1.0.2 of @code{bzip2}.  Compresseddata created by this version is entirely forwards and backwardscompatible with the previous public releases, versions 0.1pl2, 0.9.0,0.9.5, 1.0.0 and 1.0.1, but with the following exception: 0.9.0 andabove can correctly decompress multiple concatenated compressed files.0.1pl2 cannot do this; it will stop after decompressing just the firstfile in the stream.@code{bzip2recover} versions prior to this one, 1.0.2, used 32-bitintegers to represent bit positions in compressed files, so it could nothandle compressed files more than 512 megabytes long.  Version 1.0.2 andabove uses 64-bit ints on some platforms which support them (GNUsupported targets, and Windows).  To establish whether or not@code{bzip2recover} was built with such a limitation, run it withoutarguments.  In any event you can build yourself an unlimited version ifyou can recompile it with @code{MaybeUInt64} set to be an unsigned64-bit integer.@unnumberedsubsubsec AUTHORJulian Seward, @code{jseward@@acm.org}.@code{http://sources.redhat.com/bzip2}The ideas embodied in @code{bzip2} are due to (at least) the followingpeople: Michael Burrows and David Wheeler (for the block sortingtransformation), David Wheeler (again, for the Huffman coder), PeterFenwick (for the structured coding model in the original @code{bzip},and many refinements), and Alistair Moffat, Radford Neal and Ian Witten(for the arithmetic coder in the original @code{bzip}).  I am muchindebted for their help, support and advice.  See the manual in thesource distribution for pointers to sources of documentation.  Christianvon Roques encouraged me to look for faster sorting algorithms, so as tospeed up compression.  Bela Lubkin encouraged me to improve theworst-case compression performance.  The @code{bz*} scripts are derivedfrom those of GNU @code{gzip}.  Many people sent patches, helped withportability problems, lent machines, gave advice and were generallyhelpful.@end quotation@chapter Programming with @code{libbzip2}This chapter describes the programming interface to @code{libbzip2}.For general background information, particularly about memoryuse and performance aspects, you'd be well advised to read Chapter 2as well.@section Top-level structure@code{libbzip2} is a flexible library for compressing and decompressingdata in the @code{bzip2} data format.  Although packaged as a singleentity, it helps to regard the library as three separate parts: the lowlevel interface, and the high level interface, and some utilityfunctions.The structure of @code{libbzip2}'s interfaces is similar tothat of Jean-loup Gailly's and Mark Adler's excellent @code{zlib} library.All externally visible symbols have names beginning @code{BZ2_}.This is new in version 1.0.  The intention is to minimise pollutionof the namespaces of library clients.@subsection Low-level summaryThis interface provides services for compressing and decompressingdata in memory.  There's no provision for dealing with files, streamsor any other I/O mechanisms, just straight memory-to-memory work.In fact, this part of the library can be compiled without inclusionof @code{stdio.h}, which may be helpful for embedded applications.The low-level part of the library has no global variables andis therefore thread-safe.Six routines make up the low level interface: @code{BZ2_bzCompressInit}, @code{BZ2_bzCompress}, and @* @code{BZ2_bzCompressEnd}for compression,and a corresponding trio @code{BZ2_bzDecompressInit}, @* @code{BZ2_bzDecompress}and @code{BZ2_bzDecompressEnd} for decompression.  The @code{*Init} functions allocatememory for compression/decompression and do otherinitialisations, whilst the @code{*End} functions close down operationsand release memory.The real work is done by @code{BZ2_bzCompress} and @code{BZ2_bzDecompress}.  These compress and decompress data from a user-supplied input bufferto a user-supplied output buffer.  These buffers can be any size;arbitrary quantities of data are handled by making repeated callsto these functions.  This is a flexible mechanism allowing a consumer-pull style of activity, or producer-push, or a mixture ofboth.@subsection High-level summaryThis interface provides some handy wrappers around the low-levelinterface to facilitate reading and writing @code{bzip2} formatfiles (@code{.bz2} files).  The routines provide hooks to facilitatereading files in which the @code{bzip2} data stream is embedded within some larger-scale file structure, or where there aremultiple @code{bzip2} data streams concatenated end-to-end.For reading files, @code{BZ2_bzReadOpen}, @code{BZ2_bzRead},@code{BZ2_bzReadClose} and @* @code{BZ2_bzReadGetUnused} are supplied.  Forwriting files, @code{BZ2_bzWriteOpen}, @code{BZ2_bzWrite} and@code{BZ2_bzWriteFinish} are available.As with the low-level library, no global variables are usedso the library is per se thread-safe.  However, if I/O errorsoccur whilst reading or writing the underlying compressed files,you may have to consult @code{errno} to determine the cause ofthe error.  In that case, you'd need a C library which correctlysupports @code{errno} in a multithreaded environment.To make the library a little simpler and more portable,@code{BZ2_bzReadOpen} and @code{BZ2_bzWriteOpen} require you to pass them filehandles (@code{FILE*}s) which have previously been opened for reading orwriting respectively.  That avoids portability problems associated withfile operations and file attributes, whilst not being much of animposition on the programmer.@subsection Utility functions summaryFor very simple needs, @code{BZ2_bzBuffToBuffCompress} and@code{BZ2_bzBuffToBuffDecompress} are provided.  These compressdata in memory from one buffer to another buffer in a singlefunction call.  You should assess whether these functionsfulfill your memory-to-memory compression/decompressionrequirements before investing effort in understanding the moregeneral but more complex low-level interface.Yoshioka Tsuneo (@code{QWF00133@@niftyserve.or.jp} /@code{tsuneo-y@@is.aist-nara.ac.jp}) has contributed some functions togive better @code{zlib} compatibility.  These functions are@code{BZ2_bzopen}, @code{BZ2_bzread}, @code{BZ2_bzwrite}, @code{BZ2_bzflush},@code{BZ2_bzclose},@code{BZ2_bzerror} and @code{BZ2_bzlibVersion}.  You may find these functionsmore convenient for simple file reading and writing, than those in thehigh-level interface.  These functions are not (yet) officially part ofthe library, and are minimally documented here.  If they break, youget to keep all the pieces.  I hope to document them properly when timepermits.Yoshioka also contributed modifications to allow the library to bebuilt as a Windows DLL.@section Error handlingThe library is designed to recover cleanly in all situations, includingthe worst-case situation of decompressing random data.  I'm not 100% sure that it can always do this, so you might want to adda signal handler to catch segmentation violations during decompressionif you are feeling especially paranoid.  I would be interested inhearing more about the robustness of the library to corruptedcompressed data.Version 1.0 is much more robust in this respect than0.9.0 or 0.9.5.  Investigations with Checker (a tool for detecting problems with memory management, similar to Purify)indicate that, at least for the few files I tested, all single-biterrors in the decompressed data are caught properly, with nosegmentation faults, no reads of uninitialised data and no out of range reads or writes.  So it's certainly much improved,although I wouldn't claim it to be totally bombproof.The file @code{bzlib.h} contains all definitions needed to usethe library.  In particular, you should definitely not include@code{bzlib_private.h}.In @code{bzlib.h}, the various return values are defined.  The followinglist is not intended as an exhaustive description of the circumstances in which a given value may be returned -- those descriptions are givenlater.  Rather, it is intended to convey the rough meaning of eachreturn value.  The first five actions are normal and not intended to denote an error situation.@table @code@item BZ_OKThe requested action was completed successfully.@item BZ_RUN_OK@itemx BZ_FLUSH_OK@itemx BZ_FINISH_OKIn @code{BZ2_bzCompress}, the requested flush/finish/nothing-special actionwas completed successfully.@item BZ_STREAM_ENDCompression of data was completed, or the logical stream end wasdetected during decompression.@end table

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -