public static function fromFile(string $filename, bool $allowGuessByExtension): MediaType
    {
        $result = 'application/octet-stream';

        if (!@is_file($filename) || !@is_readable($filename)) {
            return new self($result);
        }

        $result = self::guessFromFinfo($filename);
        if (self::isFallback($result)) {
            $result = self::guessFromFileCommand($filename);
        }

        if ($allowGuessByExtension && self::isFallback($result)) {
            $extension = pathinfo($filename, PATHINFO_EXTENSION);
            if (self::isKnownExtension($extension)) {
                return self::fromExtension($extension);
            }
        }

        $result = str_replace(['charset=binary', 'charset=us-ascii'], ['', ''], strtolower($result));
        $result = rtrim($result, '; ');

        return new self($result);
    }