public void Unpack(InputBitStream intputBitStream, SubstringUnpacker unpacker)
		{
			var offsetReaders = offsets.Select(x=>x.Read(intputBitStream).GetEnumerator()).ToArray();
			bool hasEof = false;
			foreach (var symbol in symbols.Read(intputBitStream))
			{
				if (symbol == EofMarker)
				{
					hasEof = true;
					break;
				}
				if (symbol < 256)
				{
					unpacker.EncodeLiteral((byte)symbol);
					continue;
				}
				int len = symbol - 256;
				int offset = 0;
				for (int i = 0; i < offsetReaders.Length; i++)
				{
					var moveNext = offsetReaders[i].MoveNext();
					if (moveNext == false)
						throw new InvalidDataException("Expected offset, but got end of stream");
					offset |= offsetReaders[i].Current << (i*4);
				}
				offset = -offset;
				unpacker.EncodeSubstring(offset, len);
			}
			if(hasEof==false)
				throw new InvalidDataException("End of stream before EOF marker");
		}
 public byte[] Decompress(Stream compressed)
 {
     using (var bitStream = new InputBitStream(compressed, leaveOpen: true))
     {
         var unpacker = new SubstringUnpacker(_dictionary);
         _packer.Unpack(bitStream, unpacker);
         return unpacker.UncompressedData();
     }
 }
		public IEnumerable<int> Read(InputBitStream input)
		{
			var curr = _root;
			while (input.MoveNext())
			{
				curr = input.Current ? curr.Right : curr.Left;
				if (curr.IsBranch)
					continue;
				yield return curr.Symbol;
				curr = _root;
			}
		}
Esempio n. 4
0
        public IEnumerable <int> Read(InputBitStream input)
        {
            var curr = _root;

            while (input.MoveNext())
            {
                curr = input.Current ? curr.Right : curr.Left;
                if (curr.IsBranch)
                {
                    continue;
                }
                yield return(curr.Symbol);

                curr = _root;
            }
        }