Risuko
Node.js API

Task Operations

Add, control, and query downloads with the Node.js API.

Adding Downloads

All add* functions return a GID (Global ID) string that identifies the download task.

addUri, addTorrent, and addEd2k have corresponding JSON-RPC methods. addMagnet, addM3u8, and addFtp are available only through the Node.js bindings — they call the engine manager directly (not via RPC).

addUri

Download from one or more HTTP/HTTPS URLs. Multiple URLs are treated as mirrors for the same file.

function addUri(
  uris: string[],
  options?: Record<string, unknown>
): Promise<string>;
const gid = await addUri(
  ["https://mirror1.example.com/file.zip", "https://mirror2.example.com/file.zip"],
  { split: "16", dir: "/downloads", out: "file.zip" }
);

addTorrent

Download from a .torrent file. Pass the raw file contents as a Buffer.

function addTorrent(
  data: Buffer,
  options?: Record<string, unknown>
): Promise<string>;
import { readFile } from "node:fs/promises";

const torrentData = await readFile("./ubuntu.torrent");
const gid = await addTorrent(torrentData, { dir: "/downloads" });

addMagnet

Download from a magnet link.

function addMagnet(
  uri: string,
  options?: Record<string, unknown>
): Promise<string>;
const gid = await addMagnet("magnet:?xt=urn:btih:abc123...", {
  dir: "/downloads",
  "seed-ratio": "1.0",
});

addEd2k

Download using the ED2K protocol.

function addEd2k(
  uri: string,
  options?: Record<string, unknown>
): Promise<string>;

addM3u8

Download an M3U8/HLS stream.

function addM3u8(
  uri: string,
  options?: Record<string, unknown>
): Promise<string>;

addFtp

Download from an FTP/SFTP server.

function addFtp(
  uri: string,
  options?: Record<string, unknown>
): Promise<string>;

Task Options

Options are passed as a flat object with string values. Common options:

KeyDescriptionExample
dirDownload directory"/downloads"
outOutput filename"file.zip"
splitNumber of connections"16"
headerHTTP headers (array)["Cookie: foo=bar"]
user-agentUser agent string"MyApp/1.0"
all-proxyProxy URL"http://proxy:8080"
refererHTTP referer"https://example.com"
seed-ratioBT seed ratio"1.0"
seed-timeBT seed time (minutes)"60"
max-download-limitSpeed limit (bytes/s)"1048576"

Controlling Downloads

pause

Pause an active download.

function pause(gid: string): Promise<void>;

unpause

Resume a paused download.

function unpause(gid: string): Promise<void>;

remove

Remove a download. Active downloads are stopped first.

function remove(gid: string): Promise<void>;

pauseAll / unpauseAll

Pause or resume all downloads at once.

function pauseAll(): Promise<void>;
function unpauseAll(): Promise<void>;

Example

import { addUri, pause, unpause, remove } from "@risuko/risuko-js";

const gid = await addUri(["https://example.com/file.zip"]);

await pause(gid);     // Pause
await unpause(gid);   // Resume
await remove(gid);    // Remove

Queries

tellStatus

Get the status of a specific download. Optionally filter which fields to return.

function tellStatus(
  gid: string,
  keys?: string[]
): Promise<Record<string, unknown>>;
const status = await tellStatus(gid);
// { gid, status, totalLength, completedLength, downloadSpeed, ... }

// Request specific fields only
const partial = await tellStatus(gid, ["status", "completedLength"]);

Status Fields

FieldTypeDescription
gidstringGlobal ID
statusstring"active", "waiting", "paused", "complete", "removed", "error"
totalLengthstringTotal file size in bytes
completedLengthstringDownloaded bytes
downloadSpeedstringCurrent download speed (bytes/s)
uploadSpeedstringCurrent upload speed (bytes/s)
filesobject[]Array of file information
errorCodestringError code (if status is "error")
errorMessagestringError description

tellActive

Get all active downloads.

function tellActive(
  keys?: string[]
): Promise<Record<string, unknown>[]>;

tellWaiting

Get waiting downloads with pagination.

function tellWaiting(
  offset: number,
  num: number,
  keys?: string[]
): Promise<Record<string, unknown>[]>;

tellStopped

Get stopped downloads (complete, error, removed) with pagination.

function tellStopped(
  offset: number,
  num: number,
  keys?: string[]
): Promise<Record<string, unknown>[]>;

getGlobalStat

Get global transfer statistics.

function getGlobalStat(): Promise<Record<string, unknown>>;
const stat = await getGlobalStat();
// { downloadSpeed, uploadSpeed, numActive, numWaiting, numStopped }

getFiles

Get the file list for a download.

function getFiles(gid: string): Promise<Record<string, unknown>[]>;

getPeers

Get connected peers for a BitTorrent download.

function getPeers(gid: string): Promise<Record<string, unknown>[]>;

getUris

Get the URI list for a download.

function getUris(gid: string): Promise<Record<string, unknown>[]>;

On this page