WP_Http_Encoding::decompress() WordPress Method

The WP_Http_Encoding::decompress() method decompresses a string of encoded data. The method takes a string of encoded data and an optional integer value for the level of compression. The default level of compression is 9. The method returns a decompressed string on success or false on failure.

WP_Http_Encoding::decompress( string $compressed, int $length = null ) #

Decompression of deflated string.


Description

Will attempt to decompress using the RFC 1950 standard, and if that fails then the RFC 1951 standard deflate will be attempted. Finally, the RFC 1952 standard gzip decode will be attempted. If all fail, then the original compressed string will be returned.


Top ↑

Parameters

$compressed

(string)(Required)String to decompress.

$length

(int)(Optional)The optional length of the compressed data.

Default value: null


Top ↑

Return

(string|false) Decompressed string on success, false on failure.


Top ↑

Source

File: wp-includes/class-wp-http-encoding.php

	public static function decompress( $compressed, $length = null ) {

		if ( empty( $compressed ) ) {
			return $compressed;
		}

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

		$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;
	}


Top ↑

Changelog

Changelog
VersionDescription
2.8.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.