byte[] DecompressLZS() { while (!IsFinished) { bool isCompressed = Input.BooleanMSB(); if (isCompressed) // Compressed bytes follow. { int offsetCode = Input.ReadMSB(1); // 0 for 11 bits offset, 1 for 7 bits offset and possible end marker. int offset = Input.ReadMSB(offsetCode == 1 ? 7 : 11); if (offset == 0) { // Zero offset is an end marker for the 7-bit offset length. if (offsetCode == 1) { break; } throw new InvalidDataException("Zero offset."); } int count = ReadLZSRunLength(); if (count == 0) { throw new InvalidDataException("Length mismatch."); } WriteMemory(offset, count); } else // Literal byte follows { byte literal = (byte)Input.ReadMSB(8); Write(literal); } } CheckEnd(); return(OutputData); }