/// <summary> /// Decodes the specified data. /// </summary> public override byte[] Decode(byte[] data, FilterParms parms) { MemoryStream msInput = new MemoryStream(data); MemoryStream msOutput = new MemoryStream(); InflaterInputStream iis = new InflaterInputStream(msInput, new Inflater(false)); int cbRead; byte[] abResult = new byte[32768]; do { cbRead = iis.Read(abResult, 0, abResult.Length); if (cbRead > 0) { msOutput.Write(abResult, 0, cbRead); } }while (cbRead > 0); iis.Close(); msOutput.Flush(); if (msOutput.Length >= 0) { if (parms.DecodeParms != null) { return(StreamDecoder.Decode(msOutput.ToArray(), parms.DecodeParms)); } return(msOutput.ToArray()); } return(null); }
/// <summary> /// Decodes the specified data. /// </summary> public override byte[] Decode(byte[] data, FilterParms parms) { if (data[0] == 0x00 && data[1] == 0x01) { throw new Exception("LZW flavour not supported."); } MemoryStream outputStream = new MemoryStream(); InitializeDictionary(); _data = data; _bytePointer = 0; _nextData = 0; _nextBits = 0; int code, oldCode = 0; byte[] str; while ((code = NextCode) != 257) { if (code == 256) { InitializeDictionary(); code = NextCode; if (code == 257) { break; } outputStream.Write(_stringTable[code], 0, _stringTable[code].Length); oldCode = code; } else { if (code < _tableIndex) { str = _stringTable[code]; outputStream.Write(str, 0, str.Length); AddEntry(_stringTable[oldCode], str[0]); oldCode = code; } else { str = _stringTable[oldCode]; outputStream.Write(str, 0, str.Length); AddEntry(str, str[0]); oldCode = code; } } } if (outputStream.Length >= 0) { if (parms.DecodeParms != null) { return(StreamDecoder.Decode(outputStream.ToArray(), parms.DecodeParms)); } return(outputStream.ToArray()); } return(null); }