IKHSAN
ENID Baca dalam Bahasa Indonesia

pixies

Public
Branch
master
Latest commit
9b0697f26 October 2026

loadCloudflare.js

Open raw
import fs from 'node:fs';
import path from 'node:path';
import { cloudflareVersion, cloudflareList } from '../../config/binaries.js';
import { tmpFile, downloadToFile, extractBinary } from './downloadHelper.js';

const binaryName = `cfspeedtest${process.platform === 'win32' ? '.exe' : ''}`;
const binaryRegex = /cfspeedtest(.exe)?$/;
const binaryDirectory = path.join(process.cwd(), 'bin');
const binaryPath = path.join(binaryDirectory, binaryName);
const downloadBaseURL = `https://github.com/code-inflation/cfspeedtest/releases/download/v${cloudflareVersion}/`;

export const fileExists = async () => fs.existsSync(binaryPath);

export const downloadFile = async () => {
    let binary = cloudflareList.find(b => b.os === process.platform && b.arch === process.arch);

    if (!binary && process.platform === 'darwin')
        binary = cloudflareList.find(b => b.os === 'darwin' && b.arch === 'universal');

    if (!binary)
        throw new Error(`Your platform (${process.platform}-${process.arch}) is not supported by the Cloudflare CLI`);

    const archivePath = tmpFile(binary.suffix);
    await downloadToFile(downloadBaseURL + binary.suffix, archivePath);
    await extractBinary(archivePath, binaryDirectory, binaryRegex, binaryName);
};

export const load = async () => {
    if (!await fileExists()) await downloadFile();
};
bytes
1,340
lines
31
Type
js
Latest commit
26 October 2026