Skip to content

[Bug]: Passing extensio, doesn't do anything #67

@AlexGolubovskij

Description

@AlexGolubovskij

What happened?

Can't set extension as 'zip'.

        $extension = match ($mime_type) {
            'application/x-bzip2' => 'bz2',
            'application/gzip' => 'gz',
            'application/x-rar' => 'rar',
            'application/epub+zip' => 'epub',
            'application/pdf' => 'pdf',
            'application/zip' => 'zip',
            'application/x-tar' => 'tar',
            'application/x-7z-compressed' => '7z',
            'application/x-cbr' => 'rar',
            'application/x-cbz' => 'cbz',
            'application/x-cbt' => 'tar',
            'application/x-cb7' => '7z',
            default => null,
        };

overrides any previuosly set extension

How to reproduce the bug

call readFromString and pass $extension variable

Package Version

latest

PHP Version

8.4

Which operating systems does with happen with?

No response

Notes

public static function readFromString(string $contents, ?string $password = null, ?string $extension = null): BaseArchive
{
    $file_info = new \finfo(FILEINFO_MIME_TYPE);
    $mime_type = $file_info->buffer($contents);

    $extension = match ($mime_type) {
        'application/x-bzip2' => 'bz2',
        'application/gzip' => 'gz',
        'application/x-rar' => 'rar',
        'application/epub+zip' => 'epub',
        'application/pdf' => 'pdf',
        'application/zip' => 'zip',
        'application/x-tar' => 'tar',
        'application/x-7z-compressed' => '7z',
        'application/x-cbr' => 'rar',
        'application/x-cbz' => 'cbz',
        'application/x-cbt' => 'tar',
        'application/x-cb7' => '7z',
        default => null,
    };

    if ($extension === null) {
        throw new \Exception('Archive: Error detecting extension from mime type, please add manually archive extension as third parameter of `readFromString()`.');
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions