/** * Reads the file, detects the compression MIME type, closes the file * and returns the MIME type * * @param resource $file the file handle * * @return string the MIME type for compression, or 'none' */ public static function getCompressionMimeType($file) { //Can't use PMA_StringMB here, so force use of PMA_StringNative. include_once 'libraries/StringNative.class.php'; $pmaString = new PMA_StringNative(); $test = fread($file, 4); $len = $pmaString->strlen($test); fclose($file); if ($len >= 2 && $test[0] == $pmaString->chr(31) && $test[1] == $pmaString->chr(139)) { return 'application/gzip'; } if ($len >= 3 && $pmaString->substr($test, 0, 3) == 'BZh') { return 'application/bzip2'; } if ($len >= 4 && $test == "PK") { return 'application/zip'; } return 'none'; }
/** * Test for PMA_StringNative::substr * * @param string $str Expected substring * @param string $haystack String to check in * @param int $start Starting position of substring * @param int $length Length of substring * * @return void * @test * @dataProvider subStrData */ public function testSubStr($str, $haystack, $start, $length) { $this->assertEquals($str, $this->testObject->substr($haystack, $start, $length)); }
/** * Tests for substr * * @param mixed $value Value to test * @param int $start Position to start cutting * @param int $length Number of characters to cut * * @return void * @test * @dataProvider providerSubstr */ public function testSubstr($value, $start, $length = 2147483647) { $native = $this->_native->substr($value, $start, $length); $multibytes = $this->_mb->substr($value, $start, $length); $this->assertTrue($native === $multibytes, 'native substr: ' . var_export($native, true) . ' - mb substr: ' . var_export($multibytes, true)); }