public function decode($data)
    {
        if ($data[0] === "\x00" && $data[1] === "\x01") {
            throw new LzwException(
                'LZW flavour not supported.',
                LzwException::LZW_FLAVOUR_NOT_SUPPORTED
            );
        }

        $this->initsTable();

        $this->data = $data;
        $this->dataLength = \strlen($data);

        // Initialize pointers
        $this->bytePointer = 0;

        $this->nextData = 0;
        $this->nextBits = 0;

        $oldCode = 0;

        $uncompData = '';

        while (($code = $this->getNextCode()) !== 257) {
            if ($code === 256) {
                $this->initsTable();
                $code = $this->getNextCode();

                if ($code === 257) {
                    break;
                }

                $uncompData .= $this->sTable[$code];
                $oldCode = $code;

            } else {
                if ($code < $this->tIdx) {
                    $string = $this->sTable[$code];
                    $uncompData .= $string;

                    $this->addStringToTable($this->sTable[$oldCode], $string[0]);
                    $oldCode = $code;
                } else {
                    $string = $this->sTable[$oldCode];
                    $string .= $string[0];
                    $uncompData .= $string;

                    $this->addStringToTable($string);
                    $oldCode = $code;
                }
            }
        }

        return $uncompData;
    }
public function decode($data)
    {
        if ($data[0] === "\x00" && $data[1] === "\x01") {
            throw new LzwException(
                'LZW flavour not supported.',
                LzwException::LZW_FLAVOUR_NOT_SUPPORTED
            );
        }

        $this->initsTable();

        $this->data = $data;
        $this->dataLength = \strlen($data);

        // Initialize pointers
        $this->bytePointer = 0;

        $this->nextData = 0;
        $this->nextBits = 0;

        $oldCode = 0;

        $uncompData = '';

        while (($code = $this->getNextCode()) !== 257) {
            if ($code === 256) {
                $this->initsTable();
                $code = $this->getNextCode();

                if ($code === 257) {
                    break;
                }

                $uncompData .= $this->sTable[$code];
                $oldCode = $code;

            } else {
                if ($code < $this->tIdx) {
                    $string = $this->sTable[$code];
                    $uncompData .= $string;

                    $this->addStringToTable($this->sTable[$oldCode], $string[0]);
                    $oldCode = $code;
                } else {
                    $string = $this->sTable[$oldCode];
                    $string .= $string[0];
                    $uncompData .= $string;

                    $this->addStringToTable($string);
                    $oldCode = $code;
                }
            }
        }

        return $uncompData;
    }
public function decode ( $ data ) { if ( $ data [ 0 ] === "\x00" && $ data [ 1 ] === "\x01" ) { throw new LzwException ( 'LZW flavour not supported.' , LzwException :: LZW_FLAVOUR_NOT_SUPPORTED ) ; } $ this -> initsTable ( ) ; $ this -> data = $ data ; $ this -> dataLength = \ strlen ( $ data ) ; // Initialize pointers $ this -> bytePointer = 0 ; $ this -> nextData = 0 ; $ this -> nextBits = 0 ; $ oldCode = 0 ; $ uncompData = '' ; while ( ( $ code = $ this -> getNextCode ( ) ) !== 257 ) { if ( $ code === 256 ) { $ this -> initsTable ( ) ; $ code = $ this -> getNextCode ( ) ; if ( $ code === 257 ) { break ; } $ uncompData .= $ this -> sTable [ $ code ] ; $ oldCode = $ code ; } else { if ( $ code < $ this -> tIdx ) { $ string = $ this -> sTable [ $ code ] ; $ uncompData .= $ string ; $ this -> addStringToTable ( $ this -> sTable [ $ oldCode ] , $ string [ 0 ] ) ; $ oldCode = $ code ; } else { $ string = $ this -> sTable [ $ oldCode ] ; $ string .= $ string [ 0 ] ; $ uncompData .= $ string ; $ this -> addStringToTable ( $ string ) ; $ oldCode = $ code ; } } } return $ uncompData ; }
Method to decode LZW compressed data.

@param string $data The compressed data
@return string The uncompressed data
@throws LzwException
Method to decode LZW compressed data .