Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

aria2

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aria2 - npm Package Compare versions

Comparing version 2.0.1 to 3.0.0

27

bin/call.js

@@ -15,4 +15,4 @@ 'use strict'

}
debug('CONNECTING')
client.open(function (err) {
var cb = function (err, res) {
if (err) {

@@ -23,22 +23,9 @@ console.error(err)

debug('CONNECTED')
console.log(res)
process.exit(0)
}
var cb = function (err, res) {
debug('CLOSING')
client.close(function () {
debug('CLOSED')
if (err) {
console.error(err)
process.exit(1)
}
var args = [method].concat(params, cb)
console.log(res)
process.exit(0)
})
}
var args = [method].concat(params, cb)
client.send.apply(client, args)
})
client.send.apply(client, args)
}

@@ -18,2 +18,4 @@ aria2rpc

Uses HTTP transport.
![](./call.gif)

@@ -23,2 +25,4 @@

Uses Websocket transport.
![](./console.gif)

@@ -33,21 +33,14 @@ ;(function (global) {

var WebSocket
var b64
var httpclient
var fetch
var pg
function isNode () {
return typeof module !== 'undefined' && module.exports
}
var isNode = typeof module !== 'undefined' && module.exports
if (isNode()) {
if (isNode) {
WebSocket = require('ws')
b64 = function (str) {
return new Buffer(str).toString('base64')
}
httpclient = require('httpclient')
fetch = require('node-fetch')
pg = require('polygoat')
} else {
WebSocket = global.WebSocket
b64 = global.atob
httpclient = global.HTTPClient
fetch = global.fetch
pg = global.polygoat

@@ -66,9 +59,3 @@ }

Aria2.prototype.http = function (m, fn) {
var opts = {
'host': this.host,
'port': this.port,
'path': this.path,
'secure': this.secure
}
var that = this
var content = {

@@ -79,26 +66,21 @@ method: m.method,

// use POST (default)
if (isNode() || !this.jsonp) {
opts.body = content
opts.method = 'POST'
if (Array.isArray(m.params) && m.params.length > 0) {
opts.body.params = m.params
}
// use JSONP
} else {
opts.query = content
opts.jsonp = 'jsoncallback'
if (Array.isArray(m.params) && m.params.length > 0) {
opts.query.params = b64(JSON.stringify(m.params))
}
if (Array.isArray(m.params) && m.params.length > 0) {
content.params = m.params
}
var that = this
httpclient.request(opts, function (err, res, body) {
if (err) return fn(err)
var msg = opts.jsonp ? body : JSON.parse(body.toString())
that._onmessage(msg)
})
var url = 'http' + (this.secure ? 's' : '') + '://' + this.host + ':' + this.port + this.path
fetch(url, {
method: 'POST',
body: JSON.stringify(content),
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}})
.then(function (res) {
return res.json()
})
.then(function (msg) {
that._onmessage(msg)
})
.catch(fn)
}

@@ -323,4 +305,3 @@

'secret': '',
'path': '/jsonrpc',
'jsonp': false
'path': '/jsonrpc'
}

@@ -343,3 +324,3 @@

if (isNode()) {
if (isNode) {
module.exports = Aria2

@@ -346,0 +327,0 @@ } else {

@@ -5,21 +5,14 @@ ;(function (global) {

var WebSocket
var b64
var httpclient
var fetch
var pg
function isNode () {
return typeof module !== 'undefined' && module.exports
}
var isNode = typeof module !== 'undefined' && module.exports
if (isNode()) {
if (isNode) {
WebSocket = require('ws')
b64 = function (str) {
return new Buffer(str).toString('base64')
}
httpclient = require('httpclient')
fetch = require('node-fetch')
pg = require('polygoat')
} else {
WebSocket = global.WebSocket
b64 = global.atob
httpclient = global.HTTPClient
fetch = global.fetch
pg = global.polygoat

@@ -38,9 +31,3 @@ }

Aria2.prototype.http = function (m, fn) {
var opts = {
'host': this.host,
'port': this.port,
'path': this.path,
'secure': this.secure
}
var that = this
var content = {

@@ -51,26 +38,21 @@ method: m.method,

// use POST (default)
if (isNode() || !this.jsonp) {
opts.body = content
opts.method = 'POST'
if (Array.isArray(m.params) && m.params.length > 0) {
opts.body.params = m.params
}
// use JSONP
} else {
opts.query = content
opts.jsonp = 'jsoncallback'
if (Array.isArray(m.params) && m.params.length > 0) {
opts.query.params = b64(JSON.stringify(m.params))
}
if (Array.isArray(m.params) && m.params.length > 0) {
content.params = m.params
}
var that = this
httpclient.request(opts, function (err, res, body) {
if (err) return fn(err)
var msg = opts.jsonp ? body : JSON.parse(body.toString())
that._onmessage(msg)
})
var url = 'http' + (this.secure ? 's' : '') + '://' + this.host + ':' + this.port + this.path
fetch(url, {
method: 'POST',
body: JSON.stringify(content),
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}})
.then(function (res) {
return res.json()
})
.then(function (msg) {
that._onmessage(msg)
})
.catch(fn)
}

@@ -295,4 +277,3 @@

'secret': '',
'path': '/jsonrpc',
'jsonp': false
'path': '/jsonrpc'
}

@@ -315,3 +296,3 @@

if (isNode()) {
if (isNode) {
module.exports = Aria2

@@ -318,0 +299,0 @@ } else {

{
"name": "aria2",
"version": "2.0.1",
"version": "3.0.0",
"description": "Library and cli for aria2, \"The next generation download utility.\"",

@@ -35,3 +35,3 @@ "homepage": "https://github.com/sonnyp/aria2.js",

"commander": "^2.9.0",
"httpclient": "0.1.0",
"node-fetch": "^1.6.3",
"polygoat": "^1.1.4",

@@ -42,5 +42,7 @@ "ws": "^1.1.1"

"chai": "^3.4.1",
"mocha": "^3.1.0",
"sinon": "^1.17.2",
"sinon-chai": "^2.8.0"
"sinon-chai": "^2.8.0",
"standard": "^8.2.0"
}
}

@@ -74,3 +74,3 @@ aria2.js

- [WebSocket](https://aria2.github.io/manual/en/html/aria2c.html#json-rpc-over-websocket)
- [JSONP](https://aria2.github.io/manual/en/html/aria2c.html#json-rpc-using-http-get)
- ~~[JSONP](https://aria2.github.io/manual/en/html/aria2c.html#json-rpc-using-http-get)~~ [#25](https://github.com/sonnyp/aria2.js/pull/25)
- callback API

@@ -96,4 +96,2 @@ - promise API

```xml
<!-- optional for HTTP/JSONP support -->
<script src="node_modules/httpclient/bundle.js"></script>
<script src="node_modules/aria2/bundle.js"></script>

@@ -127,4 +125,3 @@ ```

secret: '',
path: '/jsonrpc',
jsonp: false
path: '/jsonrpc'
}

@@ -137,3 +134,3 @@ ```

`jsonp: true` will make aria2.js uses [JSONP](https://en.wikipedia.org/wiki/JSONP) for non WebSocket requests, useful if you cannot make aria2c allow your origin. It has no effect on Node.js.
For HTTP, aria2.js makes use of the new fetch standard, you might need a [polyfill](https://github.com/github/fetch) if you want to support older browsers.

@@ -140,0 +137,0 @@ [↑](#aria2js)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc