function Reader::determineFileTypeByHeader

In case ext-fileinfo is not present only the relevant types 'application/x-gzip' and 'application/x-bzip2' are resolved.

Return value

string

1 call to Reader::determineFileTypeByHeader()
Reader::determineFileType in misc/typo3/phar-stream-wrapper/src/Phar/Reader.php

File

misc/typo3/phar-stream-wrapper/src/Phar/Reader.php, line 173

Class

Reader

Namespace

TYPO3\PharStreamWrapper\Phar

Code

private function determineFileTypeByHeader() {
    $resource = fopen($this->fileName, 'r');
    if (!is_resource($resource)) {
        throw new ReaderException(sprintf('Resource %s could not be opened', $this->fileName), 1557753055);
    }
    $header = fgets($resource, 4);
    fclose($resource);
    $mimeType = '';
    if (strpos($header, "BZh") === 0) {
        $mimeType = 'application/x-bzip2';
    }
    elseif (strpos($header, "\x1f\x8b") === 0) {
        $mimeType = 'application/x-gzip';
    }
    return $mimeType;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.