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

📄 manual_3.html

📁 bzip2是一个免费的
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[ &lt;&lt; ]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual.html#SEC_Top"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[ &gt;&gt; ]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_toc.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_abt.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.3.2 <CODE>BZ2_bzCompress</CODE> </H3><!--docid::SEC20::--><TABLE><tr><td>&nbsp;</td><td class=example><pre>   int BZ2_bzCompress ( bz_stream *strm, int action );</pre></td></tr></table>Provides more input and/or output buffer space for the library.  Thecaller maintains input and output buffers, and calls <CODE>BZ2_bzCompress</CODE> totransfer data between them.<P>Before each call to <CODE>BZ2_bzCompress</CODE>, <CODE>next_in</CODE> should point atthe data to be compressed, and <CODE>avail_in</CODE> should indicate how manybytes the library may read.  <CODE>BZ2_bzCompress</CODE> updates <CODE>next_in</CODE>,<CODE>avail_in</CODE> and <CODE>total_in</CODE> to reflect the number of bytes ithas read.</P><P>Similarly, <CODE>next_out</CODE> should point to a buffer in which thecompressed data is to be placed, with <CODE>avail_out</CODE> indicating howmuch output space is available.  <CODE>BZ2_bzCompress</CODE> updates<CODE>next_out</CODE>, <CODE>avail_out</CODE> and <CODE>total_out</CODE> to reflect thenumber of bytes output.</P><P>You may provide and remove as little or as much data as you like on eachcall of <CODE>BZ2_bzCompress</CODE>.  In the limit, it is acceptable to supply andremove data one byte at a time, although this would be terriblyinefficient.  You should always ensure that at least one byte of outputspace is available at each call.</P><P>A second purpose of <CODE>BZ2_bzCompress</CODE> is to request a change of mode of thecompressed stream.  </P><P>Conceptually, a compressed stream can be in one of four states: IDLE,RUNNING, FLUSHING and FINISHING.  Before initialisation(<CODE>BZ2_bzCompressInit</CODE>) and after termination (<CODE>BZ2_bzCompressEnd</CODE>), astream is regarded as IDLE.</P><P>Upon initialisation (<CODE>BZ2_bzCompressInit</CODE>), the stream is placed in theRUNNING state.  Subsequent calls to <CODE>BZ2_bzCompress</CODE> should pass<CODE>BZ_RUN</CODE> as the requested action; other actions are illegal andwill result in <CODE>BZ_SEQUENCE_ERROR</CODE>.</P><P>At some point, the calling program will have provided all the input datait wants to.  It will then want to finish up -- in effect, asking thelibrary to process any data it might have buffered internally.  In thisstate, <CODE>BZ2_bzCompress</CODE> will no longer attempt to read data from<CODE>next_in</CODE>, but it will want to write data to <CODE>next_out</CODE>.Because the output buffer supplied by the user can be arbitrarily small,the finishing-up operation cannot necessarily be done with a single callof <CODE>BZ2_bzCompress</CODE>.</P><P>Instead, the calling program passes <CODE>BZ_FINISH</CODE> as an action to<CODE>BZ2_bzCompress</CODE>.  This changes the stream's state to FINISHING.  Anyremaining input (ie, <CODE>next_in[0 .. avail_in-1]</CODE>) is compressed andtransferred to the output buffer.  To do this, <CODE>BZ2_bzCompress</CODE> must becalled repeatedly until all the output has been consumed.  At thatpoint, <CODE>BZ2_bzCompress</CODE> returns <CODE>BZ_STREAM_END</CODE>, and the stream'sstate is set back to IDLE.  <CODE>BZ2_bzCompressEnd</CODE> should then becalled.</P><P>Just to make sure the calling program does not cheat, the library makesa note of <CODE>avail_in</CODE> at the time of the first call to<CODE>BZ2_bzCompress</CODE> which has <CODE>BZ_FINISH</CODE> as an action (ie, at thetime the program has announced its intention to not supply any moreinput).  By comparing this value with that of <CODE>avail_in</CODE> oversubsequent calls to <CODE>BZ2_bzCompress</CODE>, the library can detect anyattempts to slip in more data to compress.  Any calls for which this isdetected will return <CODE>BZ_SEQUENCE_ERROR</CODE>.  This indicates aprogramming mistake which should be corrected.</P><P>Instead of asking to finish, the calling program may ask<CODE>BZ2_bzCompress</CODE> to take all the remaining input, compress it andterminate the current (Burrows-Wheeler) compression block.  This couldbe useful for error control purposes.  The mechanism is analogous tothat for finishing: call <CODE>BZ2_bzCompress</CODE> with an action of<CODE>BZ_FLUSH</CODE>, remove output data, and persist with the<CODE>BZ_FLUSH</CODE> action until the value <CODE>BZ_RUN</CODE> is returned.  Aswith finishing, <CODE>BZ2_bzCompress</CODE> detects any attempt to provide moreinput data once the flush has begun.</P><P>Once the flush is complete, the stream returns to the normal RUNNINGstate.</P><P>This all sounds pretty complex, but isn't really.  Here's a tablewhich shows which actions are allowable in each state, what actionwill be taken, what the next state is, and what the non-error returnvalues are.  Note that you can't explicitly ask what state thestream is in, but nor do you need to -- it can be inferred from thevalues returned by <CODE>BZ2_bzCompress</CODE>.<TABLE><tr><td>&nbsp;</td><td class=display><pre style="font-family: serif">IDLE/<CODE>any</CODE>                 Illegal.  IDLE state only exists after <CODE>BZ2_bzCompressEnd</CODE> or      before <CODE>BZ2_bzCompressInit</CODE>.      Return value = <CODE>BZ_SEQUENCE_ERROR</CODE>RUNNING/<CODE>BZ_RUN</CODE>           Compress from <CODE>next_in</CODE> to <CODE>next_out</CODE> as much as possible.      Next state = RUNNING      Return value = <CODE>BZ_RUN_OK</CODE>RUNNING/<CODE>BZ_FLUSH</CODE>         Remember current value of <CODE>next_in</CODE>.  Compress from <CODE>next_in</CODE>      to <CODE>next_out</CODE> as much as possible, but do not accept any more input.        Next state = FLUSHING      Return value = <CODE>BZ_FLUSH_OK</CODE>RUNNING/<CODE>BZ_FINISH</CODE>        Remember current value of <CODE>next_in</CODE>.  Compress from <CODE>next_in</CODE>      to <CODE>next_out</CODE> as much as possible, but do not accept any more input.      Next state = FINISHING      Return value = <CODE>BZ_FINISH_OK</CODE>FLUSHING/<CODE>BZ_FLUSH</CODE>        Compress from <CODE>next_in</CODE> to <CODE>next_out</CODE> as much as possible,       but do not accept any more input.        If all the existing input has been used up and all compressed      output has been removed         Next state = RUNNING; Return value = <CODE>BZ_RUN_OK</CODE>      else         Next state = FLUSHING; Return value = <CODE>BZ_FLUSH_OK</CODE>FLUSHING/other           Illegal.      Return value = <CODE>BZ_SEQUENCE_ERROR</CODE>FINISHING/<CODE>BZ_FINISH</CODE>        Compress from <CODE>next_in</CODE> to <CODE>next_out</CODE> as much as possible,      but to not accept any more input.        If all the existing input has been used up and all compressed      output has been removed         Next state = IDLE; Return value = <CODE>BZ_STREAM_END</CODE>      else         Next state = FINISHING; Return value = <CODE>BZ_FINISHING</CODE>FINISHING/other      Illegal.      Return value = <CODE>BZ_SEQUENCE_ERROR</CODE></pre></td></tr></table></P><P>That still looks complicated?  Well, fair enough.  The usual sequenceof calls for compressing a load of data is:<UL><LI>Get started with <CODE>BZ2_bzCompressInit</CODE>.<LI>Shovel data in and shlurp out its compressed form using zero or morecalls of <CODE>BZ2_bzCompress</CODE> with action = <CODE>BZ_RUN</CODE>.<LI>Finish up.Repeatedly call <CODE>BZ2_bzCompress</CODE> with action = <CODE>BZ_FINISH</CODE>, copying out the compressed output, until <CODE>BZ_STREAM_END</CODE> is returned.<LI>Close up and go home.  Call <CODE>BZ2_bzCompressEnd</CODE>.</UL>If the data you want to compress fits into your input buffer allat once, you can skip the calls of <CODE>BZ2_bzCompress ( ..., BZ_RUN )</CODE> and just do the <CODE>BZ2_bzCompress ( ..., BZ_FINISH )</CODE> calls.<P>All required memory is allocated by <CODE>BZ2_bzCompressInit</CODE>.  Thecompression library can accept any data at all (obviously).  So youshouldn't get any error return values from the <CODE>BZ2_bzCompress</CODE> calls.If you do, they will be <CODE>BZ_SEQUENCE_ERROR</CODE>, and indicate a bug inyour programming.</P><P>Trivial other possible return values:<TABLE><tr><td>&nbsp;</td><td class=display><pre style="font-family: serif">      <CODE>BZ_PARAM_ERROR</CODE>            if <CODE>strm</CODE> is <CODE>NULL</CODE>, or <CODE>strm-&#62;s</CODE> is <CODE>NULL</CODE></pre></td></tr></table></P><P><HR SIZE="6"><A NAME="SEC21"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_3.html#SEC20"> &lt; </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_3.html#SEC22"> &gt; </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[ &lt;&lt; ]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual.html#SEC_Top"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[ &gt;&gt; ]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_toc.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_abt.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.3.3 <CODE>BZ2_bzCompressEnd</CODE> </H3><!--docid::SEC21::--><TABLE><tr><td>&nbsp;</td><td class=example><pre>int BZ2_bzCompressEnd ( bz_stream *strm );</pre></td></tr></table>Releases all memory associated with a compression stream.<P>Possible return values:<TABLE><tr><td>&nbsp;</td><td class=display><pre style="font-family: serif">   <CODE>BZ_PARAM_ERROR</CODE>    if <CODE>strm</CODE> is <CODE>NULL</CODE> or <CODE>strm-&#62;s</CODE> is <CODE>NULL</CODE>   <CODE>BZ_OK</CODE>    otherwise</pre></td></tr></table></P><P><HR SIZE="6"><A NAME="SEC22"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_3.html#SEC21"> &lt; </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_3.html#SEC23"> &gt; </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[ &lt;&lt; ]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual.html#SEC_Top"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[ &gt;&gt; ]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_toc.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_abt.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.3.4 <CODE>BZ2_bzDecompressInit</CODE> </H3><!--docid::SEC22::--><TABLE><tr><td>&nbsp;</td><td class=example><pre>int BZ2_bzDecompressInit ( bz_stream *strm, int verbosity, int small );</pre></td></tr></table>Prepares for decompression.  As with <CODE>BZ2_bzCompressInit</CODE>, a<CODE>bz_stream</CODE> record should be allocated and initialised before thecall.  Fields <CODE>bzalloc</CODE>, <CODE>bzfree</CODE> and <CODE>opaque</CODE> should beset if a custom memory allocator is required, or made <CODE>NULL</CODE> forthe normal <CODE>malloc</CODE>/<CODE>free</CODE> routines.  Upon return, the internalstate will have been initialised, and <CODE>total_in</CODE> and<CODE>total_out</CODE> will be zero.<P>For the meaning of parameter <CODE>verbosity</CODE>, see <CODE>BZ2_bzCompressInit</CODE>.</P><P>If <CODE>small</CODE> is nonzero, the library will use an alternativedecompression algorithm which uses less memory but at the cost ofdecompressing more slowly (roughly speaking, half the speed, but themaximum memory requirement drops to around 2300k).  See Chapter 2 formore information on memory management.</P><P>Note that the amount of memory needed to decompressa stream cannot be determined until the stream's header has been read,so even if <CODE>BZ2_bzDecompressInit</CODE> succeeds, a subsequent<CODE>BZ2_bzDecompress</CODE> could fail with <CODE>BZ_MEM_ERROR</CODE>.</P><P>Possible return values:<TABLE><tr><td>&nbsp;</td><td class=display><pre style="font-family: serif">      <CODE>BZ_CONFIG_ERROR</CODE>         if the library has been mis-compiled      <CODE>BZ_PARAM_ERROR</CODE>         if <CODE>(small != 0 &#38;&#38; small != 1)</CODE>         or <CODE>(verbosity &#60; 0 || verbosity &#62; 4)</CODE>      <CODE>BZ_MEM_ERROR</CODE>         if insufficient memory is available</pre></td></tr></table></P><P>

⌨️ 快捷键说明

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