'algorithm derived from:
http://www.rasip.fer.hr/research/compress/algorithms/fund/lz/lzw.html
and the PDFReference'

def decode(self):

    cW = self.CLEARDICT
    baos = ''
    while True:
        pW = cW
        cW = self.nextCode()
        if (cW == (-1)):
            raise PdfReadError('Missed    the    stop    code    in    LZWDecode!')
        if (cW == self.STOP):
            break
        elif (cW == self.CLEARDICT):
            self.resetDict()
        elif (pW == self.CLEARDICT):
            baos += self.dict[cW]
        else:
            if (cW < self.dictlen):
                baos += self.dict[cW]
                p = (self.dict[pW] + self.dict[cW][0])
                self.dict[self.dictlen] = p
                self.dictlen += 1
            else:
                p = (self.dict[pW] + self.dict[pW][0])
                baos += p
                self.dict[self.dictlen] = p
                self.dictlen += 1
            if ((self.dictlen >= ((1 << self.bitspercode) - 1)) and (self.bitspercode < 12)):
                self.bitspercode += 1
    return baos
