BattleNet.Huffman.Compress C# (CSharp) Method

Compress() public static method

public static Compress ( byte input, byte &output ) : uint
input byte
output byte
return uint
        public static uint Compress(byte[] input, out byte[] output)
        {
            if (input == null)
                throw new ArgumentNullException("input");

            uint bufferValue = 0;
            var count = 0;
            int i = input.Length,
                x = 0;
            var j = 0;
            output = new byte[input.Length];

            while (i != 0)
            {
                var a = CompressionTable[input[x++]];
                i--;
                var e = (a & 0xFF00) >> 8;

                bufferValue |= (a >> 24) << (24 - count);
                count += (int)((a & 0xFF0000) >> 16);

                if (e != 0)
                {
                    bufferValue |= ((a & 0xFF) << (int)(8 - e)) << (24 - count);
                    count += (int)e;
                }

                while (count > 8)
                {
                    output[j++] = (byte)(bufferValue >> 24);
                    count -= 8;
                    bufferValue <<= 8;
                }
            }

            while (count > 0)
            {
                output[j++] = (byte)(bufferValue >> 24);
                bufferValue <<= 8;
                count -= 8;
            }

            return (uint)j;
        }