/// <summary>
        /// Construct instance with pending buffer
        /// </summary>
        /// <param name="pending">
        /// Pending buffer to use
        /// </param>
        /// <param name="noAdlerCalculation">
        /// If no adler calculation should be performed
        /// </param>
        public DeflaterEngine(DeflaterPending pending, bool noAdlerCalculation)
        {
            this.pending = pending;
            huffman      = new DeflaterHuffman(pending);
            if (!noAdlerCalculation)
            {
                adler = new Adler32();
            }

            window = new byte[2 * DeflaterConstants.WSIZE];
            head   = new short[DeflaterConstants.HASH_SIZE];
            prev   = new short[DeflaterConstants.WSIZE];

            // We start at index 1, to avoid an implementation deficiency, that
            // we cannot build a repeat pattern at index 0.
            blockStart = strstart = 1;
        }
Exemple #2
0
        /// <summary>
        /// Creates a new deflater with given compression level.
        /// </summary>
        /// <param name="level">
        /// the compression level, a value between NO_COMPRESSION
        /// and BEST_COMPRESSION.
        /// </param>
        /// <param name="noZlibHeaderOrFooter">
        /// true, if we should suppress the Zlib/RFC1950 header at the
        /// beginning and the adler checksum at the end of the output.  This is
        /// useful for the GZIP/PKZIP formats.
        /// </param>
        /// <exception cref="System.ArgumentOutOfRangeException">if lvl is out of range.</exception>
        public Deflater(int level, bool noZlibHeaderOrFooter)
        {
            if (level == DEFAULT_COMPRESSION)
            {
                level = 6;
            }
            else if (level < NO_COMPRESSION || level > BEST_COMPRESSION)
            {
                throw new ArgumentOutOfRangeException(nameof(level));
            }

            pending = new DeflaterPending();
            engine  = new DeflaterEngine(pending, noZlibHeaderOrFooter);
            this.noZlibHeaderOrFooter = noZlibHeaderOrFooter;
            SetStrategy(DeflateStrategy.Default);
            SetLevel(level);
            Reset();
        }
 /// <summary>
 /// Construct instance with pending buffer
 /// Adler calculation will be peformed
 /// </summary>
 /// <param name="pending">
 /// Pending buffer to use
 /// </param>
 public DeflaterEngine(DeflaterPending pending)
     : this(pending, false)
 {
 }