MediaWiki  master
Deflate.php
Go to the documentation of this file.
1 <?php
24 class Deflate {
25 
33  public static function isDeflated( $data ) {
34  return substr( $data, 0, 11 ) === 'rawdeflate,';
35  }
36 
55  public static function inflate( $data ) {
56  if ( !self::isDeflated( $data ) ) {
57  throw new InvalidArgumentException( 'Data does not begin with deflated prefix' );
58  }
59  $deflated = base64_decode( substr( $data, 11 ), true );
60  if ( $deflated === false ) {
61  return StatusValue::newFatal( 'deflate-invaliddeflate' );
62  }
63  Wikimedia\suppressWarnings();
64  $inflated = gzinflate( $deflated );
65  Wikimedia\restoreWarnings();
66  if ( $inflated === false ) {
67  return StatusValue::newFatal( 'deflate-invaliddeflate' );
68  }
69  return StatusValue::newGood( $inflated );
70  }
71 }
72 
76 class_alias( Deflate::class, 'EasyDeflate' );
Deflate\inflate
static inflate( $data)
For content that has been compressed with deflate in the client, try to uncompress it with inflate.
Definition: Deflate.php:55
StatusValue\newFatal
static newFatal( $message,... $parameters)
Factory function for fatal errors.
Definition: StatusValue.php:69
Deflate
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...
Definition: Deflate.php:24
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:81
Deflate\isDeflated
static isDeflated( $data)
Whether the content is deflated.
Definition: Deflate.php:33