Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / beast / doc / html / beast / ref / boost__beast__zlib__deflate_stream / write.html
1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>zlib::deflate_stream::write</title>
5 <link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css">
6 <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7 <link rel="home" href="../../../index.html" title="Chapter&#160;1.&#160;Boost.Beast">
8 <link rel="up" href="../boost__beast__zlib__deflate_stream.html" title="zlib::deflate_stream">
9 <link rel="prev" href="upper_bound.html" title="zlib::deflate_stream::upper_bound">
10 <link rel="next" href="../boost__beast__zlib__deflate_upper_bound.html" title="zlib::deflate_upper_bound">
11 </head>
12 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13 <table cellpadding="2" width="100%"><tr>
14 <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
15 <td align="center"><a href="../../../../../../../index.html">Home</a></td>
16 <td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
17 <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18 <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19 <td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
20 </tr></table>
21 <hr>
22 <div class="spirit-nav">
23 <a accesskey="p" href="upper_bound.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../boost__beast__zlib__deflate_stream.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../boost__beast__zlib__deflate_upper_bound.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
24 </div>
25 <div class="section">
26 <div class="titlepage"><div><div><h5 class="title">
27 <a name="beast.ref.boost__beast__zlib__deflate_stream.write"></a><a class="link" href="write.html" title="zlib::deflate_stream::write">zlib::deflate_stream::write</a>
28 </h5></div></div></div>
29 <p>
30           <a class="indexterm" name="idm45873468584656"></a>
31 Compress input and write output.
32         </p>
33 <h6>
34 <a name="beast.ref.boost__beast__zlib__deflate_stream.write.h0"></a>
35           <span class="phrase"><a name="beast.ref.boost__beast__zlib__deflate_stream.write.synopsis"></a></span><a class="link" href="write.html#beast.ref.boost__beast__zlib__deflate_stream.write.synopsis">Synopsis</a>
36         </h6>
37 <pre class="programlisting"><span class="keyword">void</span>
38 <span class="identifier">write</span><span class="special">(</span>
39     <span class="identifier">z_params</span><span class="special">&amp;</span> <span class="identifier">zs</span><span class="special">,</span>
40     <span class="identifier">Flush</span> <span class="identifier">flush</span><span class="special">,</span>
41     <span class="identifier">error_code</span><span class="special">&amp;</span> <span class="identifier">ec</span><span class="special">);</span>
42 </pre>
43 <h6>
44 <a name="beast.ref.boost__beast__zlib__deflate_stream.write.h1"></a>
45           <span class="phrase"><a name="beast.ref.boost__beast__zlib__deflate_stream.write.description"></a></span><a class="link" href="write.html#beast.ref.boost__beast__zlib__deflate_stream.write.description">Description</a>
46         </h6>
47 <p>
48           This function compresses as much data as possible, and stops when the input
49           buffer becomes empty or the output buffer becomes full. It may introduce
50           some output latency (reading input without producing any output) except
51           when forced to flush. In each call, one or both of these actions are performed:
52         </p>
53 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
54 <li class="listitem">
55               Compress more input starting at <code class="computeroutput"><span class="identifier">zs</span><span class="special">.</span><span class="identifier">next_in</span></code>
56               and update <code class="computeroutput"><span class="identifier">zs</span><span class="special">.</span><span class="identifier">next_in</span></code> and <code class="computeroutput"><span class="identifier">zs</span><span class="special">.</span><span class="identifier">avail_in</span></code>
57               accordingly. If not all input can be processed (because there is not
58               enough room in the output buffer), <code class="computeroutput"><span class="identifier">zs</span><span class="special">.</span><span class="identifier">next_in</span></code>
59               and <code class="computeroutput"><span class="identifier">zs</span><span class="special">.</span><span class="identifier">avail_in</span></code> are updated and processing
60               will resume at this point for the next call.
61             </li>
62 <li class="listitem">
63               Provide more output starting at <code class="computeroutput"><span class="identifier">zs</span><span class="special">.</span><span class="identifier">next_out</span></code>
64               and update <code class="computeroutput"><span class="identifier">zs</span><span class="special">.</span><span class="identifier">next_out</span></code> and <code class="computeroutput"><span class="identifier">zs</span><span class="special">.</span><span class="identifier">avail_out</span></code>
65               accordingly. This action is forced if the parameter flush is not <code class="computeroutput"><span class="identifier">Flush</span><span class="special">::</span><span class="identifier">none</span></code>. Forcing flush frequently degrades
66               the compression ratio, so this parameter should be set only when necessary
67               (in interactive applications). Some output may be provided even if
68               flush is not set.
69             </li>
70 </ul></div>
71 <p>
72           Before the call, the application must ensure that at least one of the actions
73           is possible, by providing more input and/or consuming more output, and
74           updating <code class="computeroutput"><span class="identifier">zs</span><span class="special">.</span><span class="identifier">avail_in</span></code> or <code class="computeroutput"><span class="identifier">zs</span><span class="special">.</span><span class="identifier">avail_out</span></code>
75           accordingly; <code class="computeroutput"><span class="identifier">zs</span><span class="special">.</span><span class="identifier">avail_out</span></code> should never be zero before
76           the call. The application can consume the compressed output when it wants,
77           for example when the output buffer is full (<code class="computeroutput"><span class="identifier">zs</span><span class="special">.</span><span class="identifier">avail_out</span>
78           <span class="special">==</span> <span class="number">0</span></code>),
79           or after each call of <code class="computeroutput"><span class="identifier">write</span></code>.
80           If <code class="computeroutput"><span class="identifier">write</span></code> returns no error
81           with zero <code class="computeroutput"><span class="identifier">zs</span><span class="special">.</span><span class="identifier">avail_out</span></code>, it must be called again after
82           making room in the output buffer because there might be more output pending.
83           Normally the parameter flush is set to <code class="computeroutput"><span class="identifier">Flush</span><span class="special">::</span><span class="identifier">none</span></code>,
84           which allows deflate to decide how much data to accumulate before producing
85           output, in order to maximize compression. If the parameter flush is set
86           to <code class="computeroutput"><span class="identifier">Flush</span><span class="special">::</span><span class="identifier">sync</span></code>, all pending output is flushed to
87           the output buffer and the output is aligned on a byte boundary, so that
88           the decompressor can get all input data available so far. In particular
89           <code class="computeroutput"><span class="identifier">zs</span><span class="special">.</span><span class="identifier">avail_in</span></code> is zero after the call if enough
90           output space has been provided before the call. Flushing may degrade compression
91           for some compression algorithms and so it should be used only when necessary.
92           This completes the current deflate block and follows it with an empty stored
93           block that is three bits plus filler bits to the next byte, followed by
94           the four bytes <code class="computeroutput"><span class="special">{</span> <span class="number">0x00</span><span class="special">,</span> <span class="number">0x00</span> <span class="number">0xff</span>
95           <span class="number">0xff</span> <span class="special">}</span></code>.
96           If flush is set to <code class="computeroutput"><span class="identifier">Flush</span><span class="special">::</span><span class="identifier">partial</span></code>,
97           all pending output is flushed to the output buffer, but the output is not
98           aligned to a byte boundary. All of the input data so far will be available
99           to the decompressor, as for Z_SYNC_FLUSH. This completes the current deflate
100           block and follows it with an empty fixed codes block that is 10 bits long.
101           This assures that enough bytes are output in order for the decompressor
102           to finish the block before the empty fixed code block. If flush is set
103           to <code class="computeroutput"><span class="identifier">Flush</span><span class="special">::</span><span class="identifier">block</span></code>, a deflate block is completed and
104           emitted, as for <code class="computeroutput"><span class="identifier">Flush</span><span class="special">::</span><span class="identifier">sync</span></code>, but the output is not aligned on
105           a byte boundary, and up to seven bits of the current block are held to
106           be written as the next byte after the next deflate block is completed.
107           In this case, the decompressor may not be provided enough bits at this
108           point in order to complete decompression of the data provided so far to
109           the compressor. It may need to wait for the next block to be emitted. This
110           is for advanced applications that need to control the emission of deflate
111           blocks. If flush is set to <code class="computeroutput"><span class="identifier">Flush</span><span class="special">::</span><span class="identifier">full</span></code>,
112           all output is flushed as with <code class="computeroutput"><span class="identifier">Flush</span><span class="special">::</span><span class="identifier">sync</span></code>,
113           and the compression state is reset so that decompression can restart from
114           this point if previous compressed data has been damaged or if random access
115           is desired. Using <code class="computeroutput"><span class="identifier">Flush</span><span class="special">::</span><span class="identifier">full</span></code>
116           too often can seriously degrade compression. If <code class="computeroutput"><span class="identifier">write</span></code>
117           returns with <code class="computeroutput"><span class="identifier">zs</span><span class="special">.</span><span class="identifier">avail_out</span> <span class="special">==</span>
118           <span class="number">0</span></code>, this function must be called again
119           with the same value of the flush parameter and more output space (updated
120           <code class="computeroutput"><span class="identifier">zs</span><span class="special">.</span><span class="identifier">avail_out</span></code>), until the flush is complete
121           (<code class="computeroutput"><span class="identifier">write</span></code> returns with non-zero
122           <code class="computeroutput"><span class="identifier">zs</span><span class="special">.</span><span class="identifier">avail_out</span></code>). In the case of a <code class="computeroutput"><span class="identifier">Flush</span><span class="special">::</span><span class="identifier">full</span></code>or <code class="computeroutput"><span class="identifier">Flush</span><span class="special">::</span><span class="identifier">sync</span></code>,
123           make sure that <code class="computeroutput"><span class="identifier">zs</span><span class="special">.</span><span class="identifier">avail_out</span></code> is greater than six to avoid
124           repeated flush markers due to <code class="computeroutput"><span class="identifier">zs</span><span class="special">.</span><span class="identifier">avail_out</span>
125           <span class="special">==</span> <span class="number">0</span></code>
126           on return. If the parameter flush is set to <code class="computeroutput"><span class="identifier">Flush</span><span class="special">::</span><span class="identifier">finish</span></code>,
127           pending input is processed, pending output is flushed and deflate returns
128           the error <code class="computeroutput"><span class="identifier">error</span><span class="special">::</span><span class="identifier">end_of_stream</span></code> if there was enough output
129           space; if deflate returns with no error, this function must be called again
130           with <code class="computeroutput"><span class="identifier">Flush</span><span class="special">::</span><span class="identifier">finish</span></code> and more output space (updated
131           <code class="computeroutput"><span class="identifier">zs</span><span class="special">.</span><span class="identifier">avail_out</span></code>) but no more input data, until
132           it returns the error <code class="computeroutput"><span class="identifier">error</span><span class="special">::</span><span class="identifier">end_of_stream</span></code>
133           or another error. After <code class="computeroutput"><span class="identifier">write</span></code>
134           has returned the <code class="computeroutput"><span class="identifier">error</span><span class="special">::</span><span class="identifier">end_of_stream</span></code>
135           error, the only possible operations on the stream are to reset or destroy.
136           <code class="computeroutput"><span class="identifier">Flush</span><span class="special">::</span><span class="identifier">finish</span></code> can be used immediately after
137           initialization if all the compression is to be done in a single step. In
138           this case, <code class="computeroutput"><span class="identifier">zs</span><span class="special">.</span><span class="identifier">avail_out</span></code> must be at least value returned
139           by <code class="computeroutput"><span class="identifier">upper_bound</span></code> (see below).
140           Then <code class="computeroutput"><span class="identifier">write</span></code> is guaranteed
141           to return the <code class="computeroutput"><span class="identifier">error</span><span class="special">::</span><span class="identifier">end_of_stream</span></code> error. If not enough output
142           space is provided, deflate will not return <code class="computeroutput"><span class="identifier">error</span><span class="special">::</span><span class="identifier">end_of_stream</span></code>,
143           and it must be called again as described above. <code class="computeroutput"><span class="identifier">write</span></code>
144           returns no error if some progress has been made (more input processed or
145           more output produced), <code class="computeroutput"><span class="identifier">error</span><span class="special">::</span><span class="identifier">end_of_stream</span></code>
146           if all input has been consumed and all output has been produced (only when
147           flush is set to <code class="computeroutput"><span class="identifier">Flush</span><span class="special">::</span><span class="identifier">finish</span></code>), <code class="computeroutput"><span class="identifier">error</span><span class="special">::</span><span class="identifier">stream_error</span></code>
148           if the stream state was inconsistent (for example if <code class="computeroutput"><span class="identifier">zs</span><span class="special">.</span><span class="identifier">next_in</span></code>
149           or <code class="computeroutput"><span class="identifier">zs</span><span class="special">.</span><span class="identifier">next_out</span></code> was <code class="computeroutput"><span class="keyword">nullptr</span></code>),
150           <code class="computeroutput"><span class="identifier">error</span><span class="special">::</span><span class="identifier">need_buffers</span></code> if no progress is possible
151           (for example <code class="computeroutput"><span class="identifier">zs</span><span class="special">.</span><span class="identifier">avail_in</span></code> or <code class="computeroutput"><span class="identifier">zs</span><span class="special">.</span><span class="identifier">avail_out</span></code>
152           was zero). Note that <code class="computeroutput"><span class="identifier">error</span><span class="special">::</span><span class="identifier">need_buffers</span></code>
153           is not fatal, and <code class="computeroutput"><span class="identifier">write</span></code>
154           can be called again with more input and more output space to continue compressing.
155         </p>
156 </div>
157 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
158 <td align="left"></td>
159 <td align="right"><div class="copyright-footer">Copyright &#169; 2016-2019 Vinnie
160       Falco<p>
161         Distributed under the Boost Software License, Version 1.0. (See accompanying
162         file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
163       </p>
164 </div></td>
165 </tr></table>
166 <hr>
167 <div class="spirit-nav">
168 <a accesskey="p" href="upper_bound.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../boost__beast__zlib__deflate_stream.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../boost__beast__zlib__deflate_upper_bound.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
169 </div>
170 </body>
171 </html>