Example #1
0
        public void Decompress(Stream input, Stream output)
        {
            _input  = input;
            _output = output;

            _indexableTrie = new IndexableTrie();
            _bitReader     = new BitReader(_input);

            BuildTrie(_indexableTrie);

            int next = ReadToken();
            int last = next;

            while (_bitReader.BytesLeft > 1)
            {
                next = ReadToken();

                var lastNode = _indexableTrie[last];

                byte symbolFromTrie;
                if (next > _indexableTrie.Count)
                {
                    symbolFromTrie = GetSymbol(_indexableTrie[last]);
                }
                else
                {
                    symbolFromTrie = GetSymbol(_indexableTrie[next]);
                }
                _indexableTrie.Add(lastNode, symbolFromTrie);

                ReadString(_indexableTrie[_indexableTrie.Count].Parent);

                last = next;
            }

            ReadLastToken(next);

            _output.Flush();
        }
Example #2
0
        public void Decompress(Stream input, Stream output)
        {
            _input  = input;
            _output = output;

            _indexableTrie = new IndexableTrie();
            var bitReader = new BitReader(_input);

            while (bitReader.BytesLeft > 1)
            {
                int  bitsPerIndex = BitConverter.MinimalNumberOfBits(_indexableTrie.Count + 1);
                int  index        = BitConverter.ToInt(bitReader.Read(bitsPerIndex));
                byte symbol       = BitConverter.ToByte(bitReader.Read(8));

                if (IsOneCharString(index))
                {
                    ReadSymbol(symbol);
                }
                else
                {
                    ReadSymbols(index, symbol);
                }
            }
        }