MediaWiki REL1_39
Deflate.php
Go to the documentation of this file.
1<?php
19use Wikimedia\AtEase\AtEase;
20
26class Deflate {
27
35 public static function isDeflated( $data ) {
36 return substr( $data, 0, 11 ) === 'rawdeflate,';
37 }
38
57 public static function inflate( $data ) {
58 if ( !self::isDeflated( $data ) ) {
59 throw new InvalidArgumentException( 'Data does not begin with deflated prefix' );
60 }
61 $deflated = base64_decode( substr( $data, 11 ), true );
62 if ( $deflated === false ) {
63 return StatusValue::newFatal( 'deflate-invaliddeflate' );
64 }
65 AtEase::suppressWarnings();
66 $inflated = gzinflate( $deflated );
67 AtEase::restoreWarnings();
68 if ( $inflated === false ) {
69 return StatusValue::newFatal( 'deflate-invaliddeflate' );
70 }
71 return StatusValue::newGood( $inflated );
72 }
73}
74
78class_alias( Deflate::class, 'EasyDeflate' );
Server-side helper for client-side compressed content.
Definition Deflate.php:26
static isDeflated( $data)
Whether the content is deflated.
Definition Deflate.php:35
static inflate( $data)
For content that has been compressed with deflate in the client, try to uncompress it with inflate.
Definition Deflate.php:57