import { createRequire } from 'node:module';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const require = createRequire(import.meta.url);
const ADDON_NAME = 'rust_decoder';
export const decoderPath = () => {
    const platform = process.platform;
    const arch = process.arch;
    let targetDir;
    switch (platform) {
        case 'darwin':
            targetDir = `${ADDON_NAME}_macos`;
            break;
        case 'win32':
            if (arch === 'x64') {
                targetDir = `${ADDON_NAME}_windows_x64`;
            }
            break;
        case 'linux':
            if (arch === 'x64') {
                targetDir = `${ADDON_NAME}_linux_x64`;
            }
            else if (arch === 'arm64') {
                targetDir = `${ADDON_NAME}_linux_arm64`;
            }
            else if (arch === 'riscv64') {
                targetDir = `${ADDON_NAME}_riscv64`;
            }
            break;
        case 'freebsd':
            if (arch === 'x64') {
                targetDir = `${ADDON_NAME}_freebsd_x64`;
            }
            break;
    }
    if (!targetDir) {
        return;
    }
    return join(__dirname, '../binary', targetDir, 'decoder.node');
};
let addon;
export const getAddon = () => {
    if (!addon) {
        const addonPath = decoderPath();
        if (!addonPath) {
            return;
        }
        try {
            addon = require(addonPath);
        }
        catch {
            //
        }
    }
    return addon;
};
//# sourceMappingURL=index.js.map