Decode the GZIP stream

@return bool Successfulness
425762
public function parse()
	{
		if ($this->compressed_size >= $this->min_compressed_size)
		{
			// Check ID1, ID2, and CM
			if (substr($this->compressed_data, 0, 3) !== "\x1F\x8B\x08")
			{
				return false;
			}

			// Get the FLG (FLaGs)
			$this->flags = ord($this->compressed_data[3]);

			// FLG bits above (1 << 4) are reserved
			if ($this->flags > 0x1F)
			{
				return false;
			}

			// Advance the pointer after the above
			$this->position += 4;

			// MTIME
			$mtime = substr($this->compressed_data, $this->position, 4);
			// Reverse the string if we're on a big-endian arch because l is the only signed long and is machine endianness
			if (current(unpack('S', "\x00\x01")) === 1)
			{
				$mtime = strrev($mtime);
			}
			$this->MTIME = current(unpack('l', $mtime));
			$this->position += 4;

			// Get the XFL (eXtra FLags)
			$this->XFL = ord($this->compressed_data[$this->position++]);

			// Get the OS (Operating System)
			$this->OS = ord($this->compressed_data[$this->position++]);

			// Parse the FEXTRA
			if ($this->flags & 4)
			{
				// Read subfield IDs
				$this->SI1 = $this->compressed_data[$this->position++];
				$this->SI2 = $this->compressed_data[$this->position++];

				// SI2 set to zero is reserved for future use
				if ($this->SI2 === "\x00")
				{
					return false;
				}

				// Get the length of the extra field
				$len = current(unpack('v', substr($this->compressed_data, $this->position, 2)));
				$this->position += 2;

				// Check the length of the string is still valid
				$this->min_compressed_size += $len + 4;
				if ($this->compressed_size >= $this->min_compressed_size)
				{
					// Set the extra field to the given data
					$this->extra_field = substr($this->compressed_data, $this->position, $len);
					$this->position += $len;
				}
				else
				{
					return false;
				}
			}

			// Parse the FNAME
			if ($this->flags & 8)
			{
				// Get the length of the filename
				$len = strcspn($this->compressed_data, "\x00", $this->position);

				// Check the length of the string is still valid
				$this->min_compressed_size += $len + 1;
				if ($this->compressed_size >= $this->min_compressed_size)
				{
					// Set the original filename to the given string
					$this->filename = substr($this->compressed_data, $this->position, $len);
					$this->position += $len + 1;
				}
				else
				{
					return false;
				}
			}

			// Parse the FCOMMENT
			if ($this->flags & 16)
			{
				// Get the length of the comment
				$len = strcspn($this->compressed_data, "\x00", $this->position);

				// Check the length of the string is still valid
				$this->min_compressed_size += $len + 1;
				if ($this->compressed_size >= $this->min_compressed_size)
				{
					// Set the original comment to the given string
					$this->comment = substr($this->compressed_data, $this->position, $len);
					$this->position += $len + 1;
				}
				else
				{
					return false;
				}
			}

			// Parse the FHCRC
			if ($this->flags & 2)
			{
				// Check the length of the string is still valid
				$this->min_compressed_size += $len + 2;
				if ($this->compressed_size >= $this->min_compressed_size)
				{
					// Read the CRC
					$crc = current(unpack('v', substr($this->compressed_data, $this->position, 2)));

					// Check the CRC matches
					if ((crc32(substr($this->compressed_data, 0, $this->position)) & 0xFFFF) === $crc)
					{
						$this->position += 2;
					}
					else
					{
						return false;
					}
				}
				else
				{
					return false;
				}
			}

			// Decompress the actual data
			if (($this->data = gzinflate(substr($this->compressed_data, $this->position, -8))) === false)
			{
				return false;
			}
			else
			{
				$this->position = $this->compressed_size - 8;
			}

			// Check CRC of data
			$crc = current(unpack('V', substr($this->compressed_data, $this->position, 4)));
			$this->position += 4;
			/*if (extension_loaded('hash') && sprintf('%u', current(unpack('V', hash('crc32b', $this->data)))) !== sprintf('%u', $crc))
			{
				return false;
			}*/

			// Check ISIZE of data
			$isize = current(unpack('V', substr($this->compressed_data, $this->position, 4)));
			$this->position += 4;
			if (sprintf('%u', strlen($this->data) & 0xFFFFFFFF) !== sprintf('%u', $isize))
			{
				return false;
			}

			// Wow, against all odds, we've actually got a valid gzip string
			return true;
		}
		else
		{
			return false;
		}
	}
660833
public function parse()
    {
        if ($this->buffer === '') {
            return false;
        }
        $this->frame = null;
        $this->offset = 0;
        $this->bufferSize = strlen($this->buffer);
        while ($this->offset < $this->bufferSize) {
            if ($this->mode === self::MODE_HEADER) {
                $this->skipEmptyLines();
                if ($this->detectFrameHead()) {
                    $this->mode = self::MODE_BODY;
                } else {
                    break;
                }
            }
            if ($this->detectFrameEnd()) {
                $this->mode = self::MODE_HEADER;
            }
            break;
        }

        if ($this->offset > 0) {
            // remove parsed buffer
            $this->buffer = substr($this->buffer, $this->offset);
        }
        return $this->frame !== null;
    }
350790
protected function encode(): string
    {
        $bitmap = null;
        $lastRow = null;

        for ($y = 0; $y < $this->height; $y++) {
            $bits = null;

            for ($x = 0; $x < $this->width; $x++) {
                $bits .= $this->decoder->getBitAt($x, $y);
            }

            $bytes = str_split($bits, 8);
            $bytes[] = str_pad(array_pop($bytes), 8, '0');

            $row = null;

            foreach ($bytes as $byte) {
                $row .= sprintf('%02X', bindec($byte));
            }

            $bitmap .= $this->compress($row, $lastRow);
            $lastRow = $row;
        }

        return $bitmap;
    }
1037352
public function decompress($buffer)
    {
        $decodeBook = $this->getDecodeBook();
        $output     = '';
        $i          = 0;

        while ($i < strlen($buffer)) {
            $code = ord($buffer[$i]);

            if ($code == 254) {
                $output .= $buffer[$i + 1];
                $i      += 2;

            } else if($code == 255) {
                $len     = ord($buffer[$i + 1]);
                $output .= substr($buffer, $i + 2, $len);
                $i      += 2 + $len;

            } else {
                $output .= $decodeBook[$code];
                $i++;
            }
        }

        return $output;
    }
1163236
protected function decodeHeader()
    {
        if (isset($this->header->subject)) {
            $this->header->subject = $this->mimeHeaderDecode($this->header->subject);
        }
        if (isset($this->header->details->subject)) {
            $this->header->details->subject = $this->mimeHeaderDecode($this->header->details->subject);
        }
        if (isset($this->header->details->Subject)) {
            $this->header->details->Subject = $this->mimeHeaderDecode($this->header->details->Subject);
        }
        if (isset($this->header->from)) {
            $this->header->from = $this->mimeHeaderDecode($this->header->from);
        }
        if (isset($this->header->to)) {
            $this->header->to = $this->mimeHeaderDecode($this->header->to);
        }
    }
12818
public function getUnpacked() {
        $tries = 0;
        $obj = $this->_original;

        while ($this->_dataLooksZipped($obj)) {
            $unpacked = gzdecode($obj);
            if (null === $unpacked || false === $unpacked) {
                // If anything went wrong with decoding, return result of previous iteration
                return $obj;
            }
            $obj = $unpacked;

            $tries++;

            if ($this->_maxDepthReached($tries)) {
                // Zipped ridiculously deep? Screw that, return the original
                return $this->_original;
            }
        }
        return $obj;
    }
1315491
public function getEncoding()
    {
        if ($this->options['encoding'] === null && function_exists('mb_internal_encoding')) {
            $this->options['encoding'] = mb_internal_encoding();
        }

        return $this->options['encoding'];
    }
390239
public function decodeMpint()
    {
        $s = $this->decodeString();
        if ($s === null) {
            return null;
        }

        if ($s === '') {
            return gmp_init(0);
        }

        $n = gmp_init(bin2hex($s), 16);

        // Negative numbers: decode using two-complement.
        if (ord($s[0]) & 0x80) {
            // gmp_com() uses the number's size to compute
            // the complement, which is right in our case.
            $n = gmp_neg(gmp_add(gmp_com($n), "1"));
        }
        return $n;
    }
913513
private function decodeDeflate($fromFilename, $toFilename)
    {
        if (!function_exists('gzuncompress')) {
            throw new UserMessageException(t(/*i18n: %s is a compression method, like gzip*/'The PHP zlib extension is required in order to decode "%s" encodings.', 'deflate'));
        }
        $compressed = @file_get_contents($fromFilename);
        if ($compressed === false) {
            throw new UserMessageException(t('Failed to read the file to be decoded with inflate.'));
        }
        $isGZip = false;
        if (isset($compressed[1])) {
            $zlibHeader = unpack('n', substr($compressed, 0, 2));
            if ($zlibHeader[1] % 31 === 0) {
                $isGZip = true;
            }
        }
        if ($isGZip) {
            $decompressed = @gzuncompress($compressed);
            if ($decompressed === false) {
                throw new UserMessageException(t('Failed to decode the ZLIB compressed data.'));
            }
        } else {
            $decompressed = @gzinflate($compressed);
            if ($decompressed === false) {
                throw new UserMessageException(t('Failed to inflate the deflated data.'));
            }
        }
        if (@file_put_contents($toFilename, $decompressed) === false) {
            throw new UserMessageException(t('Failed to decompress  the file to be decoded with inflate.'));
        }
        throw new UserMessageException(t('Failed to write the deflated data.'));
    }
448965
private function deserialize($value)
    {
        $decoded = base64_decode($value, true);
        if ($decoded === false) {
            return false;
        }

        $decompressed = gzuncompress($decoded);
        return $decompressed;
    }
481504
public function read() {
		if (!is_resource($this->_resource)) {
			return false;
		}
		$meta = stream_get_meta_data($this->_resource);
		if (isset($meta['wrapper_data'])) {
			$headers = join("\r\n", $meta['wrapper_data']) . "\r\n\r\n";
		} else {
			$headers = null;
		}
		return $headers . stream_get_contents($this->_resource);
	}
1038162
public function decoded(): ?string
    {
        if (null === $this->user) {
            return null;
        }

        $userInfo = $this->getUser();
        if (null === $this->pass) {
            return $userInfo;
        }

        return $userInfo.':'.$this->getPass();
    }
311746
public static function decodeDeflate($body)
    {
        if (! function_exists('gzuncompress')) {
            require_once 'Zend/Http/Exception.php';
            throw new Zend_Http_Exception(
                'zlib extension is required in order to decode "deflate" encoding'
            );
        }

        /**
         * Some servers (IIS ?) send a broken deflate response, without the
         * RFC-required zlib header.
         *
         * We try to detect the zlib header, and if it does not exsit we
         * teat the body is plain DEFLATE content.
         *
         * This method was adapted from PEAR HTTP_Request2 by (c) Alexey Borzov
         *
         * @link http://framework.zend.com/issues/browse/ZF-6040
         */
        $zlibHeader = unpack('n', substr($body, 0, 2));
        if ($zlibHeader[1] % 31 == 0 && ord($body[0]) == 0x78 && in_array(ord($body[1]), array(0x01, 0x5e, 0x9c, 0xda))) {
            return gzuncompress($body);
        } else {
            return gzinflate($body);
        }
    }
437745
private function decodeGzip($fromFilename, $toFilename)
    {
        if (!function_exists('gzopen')) {
            throw new UserMessageException(t(/*i18n: %s is a compression method, like gzip*/'The PHP zlib extension is required in order to decode "%s" encodings.', 'gzip'));
        }
        try {
            $hFrom = @gzopen($fromFilename, 'rb');
            if ($hFrom === false) {
                throw new UserMessageException(t('Failed to open the file to be decoded with gzip.'));
            }
            $hTo = @fopen($toFilename, 'wb');
            if ($hTo === false) {
                throw new UserMessageException(t('Failed to create the file that contain gzip-decoded data.'));
            }
            while (!gzeof($hFrom)) {
                $data = @gzread($hFrom, 32768);
                if (!is_string($data) || $data === '') {
                    throw new UserMessageException(t('Failed to decode the gzip data.'));
                }
                if (@fwrite($hTo, $data) === false) {
                    throw new UserMessageException(t('Failed to write decoded gzip data.'));
                }
            }
        } catch (Exception $x) {
            if (isset($hTo) && is_resource($hTo)) {
                @fclose($hTo);
            }
            if (isset($hFrom) && is_resource($hFrom)) {
                @gzclose($hFrom);
            }
            throw $x;
        }
        fclose($hTo);
        gzclose($hFrom);
    }
642487
protected function sessionEncode()
    {
        $type = ini_get('session.serialize_handler');
        if ($type === 'php') {
            return $this->serializePHP($this->getSessionState());
        }
        if ($type === 'php_binary') {
            return igbinary_serialize($this->getSessionState());
        }
        return false;
    }
1170666
public function stream_read($length)
    {
        if ($this->fileHandle === null) {
            return false;
        }
        self::restore();
        $content = fread($this->fileHandle, $length);
        self::register();
        return $content;
    }
751753
private function convertEncoding()
    {
        $convert = new EncodingHandler($this->content, $this->encoding);
        if (($result = $convert->auto()) !== false) {
            $this->encoding = self::ENCODING;
            mb_internal_encoding(self::ENCODING);
            return $this->content = $result;
        }
        mb_internal_encoding(self::ENCODING);
        return $this->content;
    }