Ionic.Zlib.DeflateManager.SetParams C# (CSharp) Method

SetParams() private method

private SetParams ( CompressionLevel level, CompressionStrategy strategy ) : int
level CompressionLevel
strategy CompressionStrategy
return int
        internal int SetParams(CompressionLevel level, CompressionStrategy strategy)
        {
            int result = ZlibConstants.Z_OK;

            if (compressionLevel != level)
            {
                Config newConfig = Config.Lookup(level);

                // change in the deflate flavor (Fast vs slow vs none)?
                if (newConfig.Flavor != config.Flavor && _codec.TotalBytesIn != 0)
                {
                    // Flush the last buffer:
                    result = _codec.Deflate(FlushType.Partial);
                }

                compressionLevel = level;
                config = newConfig;
                SetDeflater();
            }

            // no need to flush with change in strategy?  Really?
            compressionStrategy = strategy;

            return result;
        }

Usage Example

Example #1
0
 /// <summary>
 /// Set the CompressionStrategy and CompressionLevel for a deflation session.
 /// </summary>
 /// <param name="level">the level of compression to use.</param>
 /// <param name="strategy">the strategy to use for compression.</param>
 /// <returns>Z_OK if all goes well.</returns>
 public int SetDeflateParams(CompressionLevel level, CompressionStrategy strategy)
 {
     if (dstate == null)
     {
         throw new ZlibException("No Deflate State!");
     }
     return(dstate.SetParams(level, strategy));
 }