IKHSAN
ENID Baca dalam Bahasa Indonesia

pixies

Public
Branch
master
Latest commit
9b0697f26 October 2026

loadOokla.js

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

const binaryName = `speedtest${process.platform === 'win32' ? '.exe' : ''}`;
const binaryRegex = /speedtest(.exe)?$/;
const binaryDirectory = path.join(process.cwd(), 'bin');
const binaryPath = path.join(binaryDirectory, binaryName);

const downloadPath = `https://install.speedtest.net/app/cli/ookla-speedtest-${ooklaVersion}-`;

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

export const downloadFile = async () => {
    const binary = ooklaList.find(b => b.os === process.platform && b.arch === process.arch);
    if (!binary)
        throw new Error(`Your platform (${process.platform}-${process.arch}) is not supported by the Speedtest CLI`);

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

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