public void Decode(byte[] data, Stream uncompData) {
if (data[0] == (byte)0x00 && data[1] == (byte)0x01) {
throw new Exception("LZW flavour not supported.");
}
InitializeStringTable();
this.data = data;
this.uncompData = uncompData;
// Initialize pointers
bytePointer = 0;
nextData = 0;
nextBits = 0;
int code, oldCode = 0;
byte[] str;
while ((code = this.NextCode) != 257) {
if (code == 256) {
InitializeStringTable();
code = NextCode;
if (code == 257) {
break;
}
WriteString(stringTable[code]);
oldCode = code;
} else {
if (code < tableIndex) {
str = stringTable[code];
WriteString(str);
AddStringToTable(stringTable[oldCode], str[0]);
oldCode = code;
} else {
str = stringTable[oldCode];
str = ComposeString(str, str[0]);
WriteString(str);
AddStringToTable(str);
oldCode = code;
}
}
}
}