Exemplo n.º 1
0
		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 DebugUnpackerOutput(TextReader data, SubstringUnpacker unpacker)
		{
			_data = data;
			_unpacker = unpacker;
		}
 public string DecompressDebug(string input)
 {
     var substringUnpacker = new SubstringUnpacker(_dictionary);
     var debugUnpackerOutput = new DebugUnpackerOutput(new StringReader(input), substringUnpacker);
     debugUnpackerOutput.Unpack();
     var uncompressedData = substringUnpacker.UncompressedData();
     return Encoding.UTF8.GetString(uncompressedData);
 }