Projet

Général

Profil

Révision 6b24a280

Ajouté par Assos Assos il y a presque 4 ans

-a

Voir les différences:

drupal7/misc/typo3/phar-stream-wrapper/src/Phar/Reader.php
19 19
    private $fileName;
20 20

  
21 21
    /**
22
     * Mime-type in order to use zlib, bzip2 or no compression.
23
     * In case ext-fileinfo is not present only the relevant types
24
     * 'application/x-gzip' and 'application/x-bzip2' are assigned
25
     * to this class property.
26
     *
22 27
     * @var string
23 28
     */
24 29
    private $fileType;
......
139 144
     */
140 145
    private function resolveStream()
141 146
    {
142
        if ($this->fileType === 'application/x-gzip') {
147
        if ($this->fileType === 'application/x-gzip' || $this->fileType === 'application/gzip') {
143 148
            return 'compress.zlib://';
144 149
        } elseif ($this->fileType === 'application/x-bzip2') {
145 150
            return 'compress.bzip2://';
......
152 157
     */
153 158
    private function determineFileType()
154 159
    {
155
        $fileInfo = new \finfo();
156
        return $fileInfo->file($this->fileName, FILEINFO_MIME_TYPE);
160
        if (class_exists('\\finfo')) {
161
            $fileInfo = new \finfo();
162
            return $fileInfo->file($this->fileName, FILEINFO_MIME_TYPE);
163
        }
164
        return $this->determineFileTypeByHeader();
165
    }
166

  
167
    /**
168
     * In case ext-fileinfo is not present only the relevant types
169
     * 'application/x-gzip' and 'application/x-bzip2' are resolved.
170
     *
171
     * @return string
172
     */
173
    private function determineFileTypeByHeader()
174
    {
175
        $resource = fopen($this->fileName, 'r');
176
        if (!is_resource($resource)) {
177
            throw new ReaderException(
178
                sprintf('Resource %s could not be opened', $this->fileName),
179
                1557753055
180
            );
181
        }
182
        $header = fgets($resource, 4);
183
        fclose($resource);
184
        $mimeType = '';
185
        if (strpos($header, "\x42\x5a\x68") === 0) {
186
            $mimeType = 'application/x-bzip2';
187
        } elseif (strpos($header, "\x1f\x8b") === 0) {
188
            $mimeType = 'application/x-gzip';
189
        }
190
        return $mimeType;
157 191
    }
158 192

  
159 193
    /**

Formats disponibles : Unified diff