libaria2
Version:
A full-typing wrapper around aria2`, `The next generation download utility`.
111 lines (80 loc) • 2.57 kB
Markdown




> This is a fork of [hydrati/libaria2-ts](https://github.com/hydrati/libaria2-ts).
Node.js TypeScript library for [aria2](https://aria2.github.io/).
libaria2 uses [Aria2 JSON-RPC Interface](https://aria2.github.io/manual/en/html/aria2c.html#rpc-interface) to control it.
- Multiple Transports
- [HTTP](https://aria2.github.io/manual/en/html/aria2c.html#rpc-interface)
- [WebSocket](https://aria2.github.io/manual/en/html/aria2c.html#json-rpc-over-websocket)
- Promise-based API
- Full-Typing, JSDoc
Install this package
```bash
npm install libaria2
```
Start aria2 with rpc, example
```bash
aria2c --enable-rpc --rpc-listen-all=true --rpc-allow-origin-all
```
```ts
import { WebSocket as Aria2WebSocket } from "libaria2-ts";
const aria2 = new Aria2WebSocket({
host: 'localhost',
port: 6800
});
```
```ts
import { Http as Aria2Http } from "libaria2-ts";
const aria2 = new Aria2Http({
host: 'localhost',
port: 6800
});
```
Example options
```ts
{
host: 'localhost',
port: 6800,
path: '/jsonrpc',
auth: {
secret: 'hello'
}
}
```
```ts
const version = await aria2.getVersion();
/*
* Output:
* { version: '...', enabledFeatues: [...] }
*/
const resl = await aria2.system.multicall(
{ methodName: 'aria2.getVersion', params: [] },
{ methodName: 'aria2.addUri', params: ['http://example.com/qwer.zip'] }
);
/*
* Output:
* Array<Promise<...>>
*/
// or:
aria2.on('aria2.onDownloadStart', (event: IAria2NotificationEvent) => {
console.log(`Download ${event.gid} Started`);
});
// or:
aria2.onceDownloadStart().then((event: IAria2NotificationEvent) => {
console.log(`Download ${event.gid} Started`);
});
await aria2.closeConnection();
```
More methods, see [Aria2ClientBaseClient](https://hydrati.github.io/libaria2-ts/classes/adapter.aria2clientbaseclass.html)
MIT License © 2021 [Oxygen](https://github.com/hydrati)
MIT License © 2023 [XLor](https://github.com/yjl9903)