Deflate() private method

private Deflate ( FlushType flush ) : int
flush FlushType
return int
Beispiel #1
0
 /// <summary>
 /// Deflate one batch of data.
 /// </summary>
 /// <remarks>
 /// You must have set InputBuffer and OutputBuffer before calling this method.
 /// </remarks>
 /// <example>
 /// <code>
 /// private void DeflateBuffer(CompressionLevel level)
 /// {
 ///     int bufferSize = 1024;
 ///     byte[] buffer = new byte[bufferSize];
 ///     ZlibCodec compressor = new ZlibCodec();
 ///
 ///     Console.WriteLine("\n============================================");
 ///     Console.WriteLine("Size of Buffer to Deflate: {0} bytes.", UncompressedBytes.Length);
 ///     MemoryStream ms = new MemoryStream();
 ///
 ///     int rc = compressor.InitializeDeflate(level);
 ///
 ///     compressor.InputBuffer = UncompressedBytes;
 ///     compressor.NextIn = 0;
 ///     compressor.AvailableBytesIn = UncompressedBytes.Length;
 ///
 ///     compressor.OutputBuffer = buffer;
 ///
 ///     // pass 1: deflate
 ///     do
 ///     {
 ///         compressor.NextOut = 0;
 ///         compressor.AvailableBytesOut = buffer.Length;
 ///         rc = compressor.Deflate(FlushType.None);
 ///
 ///         if (rc != ZlibConstants.Z_OK &amp;&amp; rc != ZlibConstants.Z_STREAM_END)
 ///             throw new Exception("deflating: " + compressor.Message);
 ///
 ///         ms.Write(compressor.OutputBuffer, 0, buffer.Length - compressor.AvailableBytesOut);
 ///     }
 ///     while (compressor.AvailableBytesIn &gt; 0 || compressor.AvailableBytesOut == 0);
 ///
 ///     // pass 2: finish and flush
 ///     do
 ///     {
 ///         compressor.NextOut = 0;
 ///         compressor.AvailableBytesOut = buffer.Length;
 ///         rc = compressor.Deflate(FlushType.Finish);
 ///
 ///         if (rc != ZlibConstants.Z_STREAM_END &amp;&amp; rc != ZlibConstants.Z_OK)
 ///             throw new Exception("deflating: " + compressor.Message);
 ///
 ///         if (buffer.Length - compressor.AvailableBytesOut &gt; 0)
 ///             ms.Write(buffer, 0, buffer.Length - compressor.AvailableBytesOut);
 ///     }
 ///     while (compressor.AvailableBytesIn &gt; 0 || compressor.AvailableBytesOut == 0);
 ///
 ///     compressor.EndDeflate();
 ///
 ///     ms.Seek(0, SeekOrigin.Begin);
 ///     CompressedBytes = new byte[compressor.TotalBytesOut];
 ///     ms.Read(CompressedBytes, 0, CompressedBytes.Length);
 /// }
 /// </code>
 /// </example>
 /// <param name="flush">whether to flush all data as you deflate. Generally you will want to
 /// use Z_NO_FLUSH here, in a series of calls to Deflate(), and then call EndDeflate() to
 /// flush everything.
 /// </param>
 /// <returns>Z_OK if all goes well.</returns>
 public int Deflate(FlushType flush)
 {
     if (dstate == null)
     {
         throw new ZlibException("No Deflate State!");
     }
     return(dstate.Deflate(flush));
 }