Example #1
0
 public PKLibDecompress(Stream Input)
 {
     this.mStream = new BitStream(Input);
     this.mCType = (CompressionType) Input.ReadByte();
     if ((this.mCType != CompressionType.Binary) && (this.mCType != CompressionType.Ascii))
     {
         throw new Exception("Invalid compression type: " + this.mCType);
     }
     this.mDSizeBits = Input.ReadByte();
     if ((4 > this.mDSizeBits) || (this.mDSizeBits > 6))
     {
         throw new Exception("Invalid dictionary size: " + this.mDSizeBits);
     }
 }
Example #2
0
 private static LinkedNode Decode(BitStream Input, LinkedNode Head)
 {
     LinkedNode node = Head;
     while (node.Child0 != null)
     {
         int num = Input.ReadBits(1);
         if (num == -1)
         {
             throw new Exception("Unexpected end of file");
         }
         node = (num == 0) ? node.Child0 : node.Child1;
     }
     return node;
 }
Example #3
0
        public static byte[] Decompress(Stream Data)
        {
            int decompressedValue;
            int index = Data.ReadByte();
            if (index == 0)
            {
                throw new NotImplementedException("Compression type 0 is not currently supported");
            }
            LinkedNode tail = BuildList(sPrime[index]);
            LinkedNode head = BuildTree(tail);
            MemoryStream stream = new MemoryStream();
            BitStream input = new BitStream(Data);
            do
            {
                decompressedValue = Decode(input, head).DecompressedValue;
                switch (decompressedValue)
                {
                    case 0x100:
                        break;

                    case 0x101:
                        {
                            int decomp = input.ReadBits(8);
                            stream.WriteByte((byte) decomp);
                            tail = InsertNode(tail, decomp);
                            break;
                        }
                    default:
                        stream.WriteByte((byte) decompressedValue);
                        break;
                }
            }
            while (decompressedValue != 0x100);
            return stream.ToArray();
        }