IKHSAN
EN Read in EnglishID

pixies

Publik
Branch
master
Commit terakhir
9b0697f26 Oktober 2026

loadLibre.js

Buka raw
import fs from 'node:fs';
import path from 'node:path';
import { libreVersion, libreList } from '../../config/binaries.js';
import { tmpFile, downloadToFile, extractBinary } from './downloadHelper.js';

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

const downloadPath = `https://github.com/librespeed/speedtest-cli/releases/download/v${libreVersion}/librespeed-cli_${libreVersion}_`;

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

export const downloadFile = async () => {
    const binary = libreList.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 LibreSpeed 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();
};
byte
1.212
baris
28
Jenis
js
Commit terakhir
26 Oktober 2026