/// <summary>
        /// compress the input data
        /// </summary>
        /// <param name="input">the input data</param>
        /// <param name="compressMode">the compress mode of this compress</param>
        /// <returns>compressed data, if the compressed data is larger than input data, the original data
        /// is returned</returns>
        public byte[] Compress(byte[] input, out CompressMode compressMode)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            compressMode = CompressMode.Compressed;
            if (input.Length > (window8k - slidingWindow.Count))
            {
                compressMode = compressMode | CompressMode.SetToFront;
                hashTable.Clear();
                slidingWindow.Clear();
            }

            CompressCore(input);

            byte[] ret = new byte[outputStream.Length];
            outputStream.Position = 0;
            outputStream.Read(ret, 0, ret.Length);

            //put stream position to 0 for next round compress
            outputStream.SetLength(0);

            if (ret.Length > input.Length)
            {
                compressMode = CompressMode.Flush;
                hashTable.Clear();
                slidingWindow.Clear();
                return(input);
            }

            return(ret);
        }
 /// <summary>
 /// Initialize all field of this class instance
 /// </summary>
 private void InitializeAll()
 {
     historyBuffer.Clear();
     decodeState     = DecodeState.Init;
     needMoreData    = false;
     remain          = 0;
     remainBitsCount = 0;
     offset          = 0;
     length          = 0;
     literal         = 0;
 }