gzdecode example

// Empty body does not need further processing.             return $data;
        }

        $marker = substr($data, 0, 2);
        if (!isset(self::$magic_compression_headers[$marker])) {
            // Not actually compressed. Probably cURL ruining this for us.             return $data;
        }

        if (function_exists('gzdecode')) {
            $decoded = @gzdecode($data);
            if ($decoded !== false) {
                return $decoded;
            }
        }

        if (function_exists('gzinflate')) {
            $decoded = @gzinflate($data);
            if ($decoded !== false) {
                return $decoded;
            }
        }

        
if (!$token || !file_exists($file = $this->getFilename($token))) {
            return null;
        }

        $h = fopen($file, 'r');
        flock($h, \LOCK_SH);
        $data = stream_get_contents($h);
        flock($h, \LOCK_UN);
        fclose($h);

        if (\function_exists('gzdecode')) {
            $data = @gzdecode($data) ?: $data;
        }

        if (!$data = unserialize($data)) {
            return null;
        }

        return $this->createProfileFromData($token$data$profile);
    }

    private function removeExpiredProfiles(): void
    {
        
$decompressed = self::compatible_gzinflate( $compressed );
        if ( false !== $decompressed ) {
            return $decompressed;
        }

        $decompressed = @gzuncompress( $compressed );
        if ( false !== $decompressed ) {
            return $decompressed;
        }

        if ( function_exists( 'gzdecode' ) ) {
            $decompressed = @gzdecode( $compressed );

            if ( false !== $decompressed ) {
                return $decompressed;
            }
        }

        return $compressed;
    }

    /** * Decompression of deflated string while staying compatible with the majority of servers. * * Certain Servers will return deflated data with headers which PHP's gzinflate() * function cannot handle out of the box. The following function has been created from * various snippets on the gzinflate() PHP documentation. * * Warning: Magic numbers within. Due to the potential different formats that the compressed * data may be returned in, some "magic offsets" are needed to ensure proper decompression * takes place. For a simple pragmatic way to determine the magic offset in use, see: * https://core.trac.wordpress.org/ticket/18273 * * @since 2.8.1 * * @link https://core.trac.wordpress.org/ticket/18273 * @link https://www.php.net/manual/en/function.gzinflate.php#70875 * @link https://www.php.net/manual/en/function.gzinflate.php#77336 * * @param string $gz_data String to decompress. * @return string|false Decompressed string on success, false on failure. */
if (!$token || !file_exists($file = $this->getFilename($token))) {
            return null;
        }

        $h = fopen($file, 'r');
        flock($h, \LOCK_SH);
        $data = stream_get_contents($h);
        flock($h, \LOCK_UN);
        fclose($h);

        if (\function_exists('gzdecode')) {
            $data = @gzdecode($data) ?: $data;
        }

        if (!$data = unserialize($data)) {
            return null;
        }

        return $this->createProfileFromData($token$data$profile);
    }

    private function removeExpiredProfiles(): void
    {
        
'headers' => ['Accept-Encoding' => 'gzip'],
        ]);

        $headers = $response->getHeaders();

        $this->assertSame(['Accept-Encoding']$headers['vary']);
        $this->assertStringContainsString('gzip', $headers['content-encoding'][0]);

        $body = $response->getContent();
        $this->assertSame("\x1F", $body[0]);

        $body = json_decode(gzdecode($body), true);
        $this->assertSame('gzip', $body['HTTP_ACCEPT_ENCODING']);
    }

    /** * @requires extension zlib */
    public function testGzipBroken()
    {
        $client = $this->getHttpClient(__FUNCTION__);
        $response = $client->request('GET', 'http://localhost:8057/gzip-broken');

        
break;

                                    case 'deflate':
                                        if (($decompressed = gzinflate($this->body)) !== false)
                                        {
                                            $this->body = $decompressed;
                                        }
                                        else if (($decompressed = gzuncompress($this->body)) !== false)
                                        {
                                            $this->body = $decompressed;
                                        }
                                        else if (function_exists('gzdecode') && ($decompressed = gzdecode($this->body)) !== false)
                                        {
                                            $this->body = $decompressed;
                                        }
                                        else
                                        {
                                            $this->error = 'Unable to decode HTTP "deflate" stream';
                                            $this->success = false;
                                        }
                                        break;

                                    default:
                                        
Home | Imprint | This part of the site doesn't use cookies.