Example #1
0
        /// <summary>
        /// Creates a Decompressor object for use in decompressing data dynamically.
        /// </summary>
        /// <param name="Callback">A function that will be called for each compressed
        /// output byte.</param>
        public Decompressor(OutputByte Callback)
        {
            if (Callback == null)
            {
                throw new Exception("A Callback function must be specified");
            }

            this.Callback = Callback;

            stack  = new Stack <byte>(8192);
            prefix = new ushort[Compressor.MaxCode];
            suffix = new byte[Compressor.MaxCode];

            // Just a small buffer to hold input bytes between calls to Decode().
            inQueue = new Queue <byte>();

            outBits   = 0;
            inBits    = Compressor.nBits;
            crc       = 0;
            freeEntry = Compressor.FirstCode;

            for (short i = 255; i >= 0; i--)
            {
                prefix[i] = 0;
                suffix[i] = (byte)i;
            }
        }
        /// <summary>
        /// Creates a Decompressor object for use in decompressing data dynamically.
        /// </summary>
        /// <param name="Callback">A function that will be called for each compressed
        /// output byte.</param>
        public Decompressor(OutputByte Callback)
        {
            if (Callback == null)
                throw new Exception("A Callback function must be specified");

            this.Callback = Callback;

            stack = new Stack<byte>(8192);
            prefix = new ushort[Compressor.MaxCode];
            suffix = new byte[Compressor.MaxCode];

            // Just a small buffer to hold input bytes between calls to Decode().
            inQueue = new Queue<byte>();

            outBits = 0;
            inBits = Compressor.nBits;
            crc = 0;
            freeEntry = Compressor.FirstCode;

            for (short i = 255; i >= 0; i--)
            {
                prefix[i] = 0;
                suffix[i] = (byte)i;
            }
        }
        /// <summary>
        /// Creates a Compressor object for use in compressing data dynamically.
        /// </summary>
        /// <param name="Callback">A function that will be called for each decompressed
        /// output byte.</param>
        public Compressor(OutputByte Callback)
        {
            if (nBits < MinBits || nBits > MaxBits)
            {
                throw new Exception("Invalid value for 'nBits'");
            }
            if (Callback == null)
            {
                throw new Exception("A Callback function must be specified");
            }

            this.Callback = Callback;

            hashSize  = primes[nBits - MinBits];
            hashTable = new int[hashSize];
            codeTable = new ushort[hashSize];

            short j = 0;

            for (int fc = hashSize; fc < 65536L; fc *= 2)
            {
                j++;
            }
            shift = (short)(8 - j);

            ClearHash();
        }
        /// <summary>
        /// Creates a Compressor object for use in compressing data dynamically.
        /// </summary>
        /// <param name="Callback">A function that will be called for each decompressed
        /// output byte.</param>
        public Compressor(OutputByte Callback)
        {
            if (nBits < MinBits || nBits > MaxBits)
                throw new Exception("Invalid value for 'nBits'");
            if (Callback == null)
                throw new Exception("A Callback function must be specified");

            this.Callback = Callback;

            hashSize = primes[nBits - MinBits];
            hashTable = new int[hashSize];
            codeTable = new ushort[hashSize];

            short j = 0;
            for (int fc = hashSize; fc < 65536L; fc *= 2)
                j++;
            shift = (short)(8 - j);

            ClearHash();
        }