New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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 0.0.2 to 0.0.3

112

aria2.js

@@ -0,1 +1,2 @@

!function(a){"use strict";var b=function(a,b,c){b=b||"&",c=c||"=";var d="";if("object"==typeof a){for(var e in a)d+=e+c+a[e]+b;d.length>0&&(d="?"+d.slice(0,-1))}return d},c=function(a){var c=b(a.query);return[a.secure?"https":"http","://",a.host,a.port?":"+a.port:"",a.path||"/",c,a.hash||""].join("")},d=a.XMLHttpRequest,e=function(){},f=function(b,d){var e=b.query[b.jsonp],f=c(b),g=document.createElement("script");g.src=f,g.async=!0,a[e]=function(b){d(null,b),delete a[e],delete g.onerror,g.parentNode.remove(g)},g.onerror=function(b){d(b),delete g.onerror,delete a[e],g.parentNode.remove(g)};var h=document.head||document.getElementsByTagName("head")[0];h.appendChild(g)},g=function(a){for(var b=["response","error","end"],g=0;g<b.length;g++)this["on"+b[g]]=e;var h=HTTPClient.utils.handleOptions(a);for(var i in h)this[i]=h[i];if("string"==typeof h.jsonp)return void f(h,function(a,b){a?this.onerror(a):this.onend(b)}.bind(this));var j=new d;j.addEventListener("error",function(a){this.onerror(a)}.bind(this)),j.addEventListener("readystatechange",function(){if(2===j.readyState){var a={},b=j.getAllResponseHeaders();if(b)for(var c=b.split("\n"),d=0;d<c.length;d++)if(c[d]){var e=c[d].split(":");a[e[0].toLowerCase()]=e.slice(1).join().trim()}var f=j.status;this.onresponse({headers:a,status:f,type:HTTPClient.utils.getTypeFromHeaders(a)})}else 4===j.readyState&&this.onend(j.response)}.bind(this)),j.open(h.method,c(h),!0);for(var k in h.headers)j.setRequestHeader(k,h.headers[k]);j.send(h.body),this.req=j};g.prototype.abort=function(){this.req.abort()},a.HTTPRequest=g}(this),function(a){"use strict";var b;b="undefined"!=typeof module&&module.exports?require("./lib/node"):a.HTTPRequest;var c=function(a,c){if(!c)return new b(a);var d=new b(a);d.onerror=function(a){c(a)};var e;return d.onresponse=function(a){e=a},d.onend=function(a){e=e||{},e.body=a,c(null,e)},d};"undefined"!=typeof module&&module.exports?module.exports=c:a.HTTPClient=c}(this),function(a){"use strict";var b;b="undefined"!=typeof Buffer?function(a){return new Buffer(a).toString("base64")}:a.btoa;var c=function(a){return Object.getPrototypeOf?Object.getPrototypeOf(a):a.__proto__},d=c({}),e=function(a){return"object"!=typeof a?!1:c(a)===d||null===c(a)},f=function(a){var c={};c.query="object"==typeof a.query?a.query:{},c.secure=!!a.secure||!1,c.port=a.port||(c.secure?443:80),c.host=a.host||"localhost",c.path=a.path||"/",c.headers="object"==typeof a.headers?a.headers:{},c.method="string"==typeof a.method?a.method.toUpperCase():"GET",a.jsonp===!0&&(a.jsonp="callback"),"string"==typeof a.jsonp&&(c.jsonp=a.jsonp,c.query[a.jsonp]="HTTPClient"+Date.now());for(var d in c.headers){var f=c.headers[d];delete c.headers[d],c.headers[d.toLowerCase()]=f}if("string"==typeof a.username&&"string"==typeof a.password){var g=a.username+":"+a.password;c.headers.authorization="Basic "+b(g)}return Array.isArray(a.body)||e(a.body)?(c.body=JSON.stringify(a.body),c.headers["tontent-type"]||(c.headers["content-type"]="application/json; charset=utf-8")):"string"==typeof a.body?(c.body=a.body,c.headers["content-type"]||(c.headers["content-type"]="text/plain; charset=utf-8")):(void 0!==a.body||null!==a.body)&&(c.body=a.body),c},g=function(a){var b="";if("object"==typeof a){var c=a["content-type"];c&&(b=c.split(";")[0])}return b},h={handleOptions:f,getTypeFromHeaders:g,getPrototypeOf:c};"undefined"!=typeof module&&module.exports?module.exports=h:a.HTTPClient.utils=h}(this);
(function(global) {

@@ -7,3 +8,3 @@

var b64;
var http;
var httpclient;;
if (typeof module !== 'undefined' && module.exports) {

@@ -14,59 +15,8 @@ WebSocket = require('ws');

};
var httpclient = require('httpclient');
http = function(m, fn) {
//FIXME json-rpc post won't work
var opts = {
host: this.host,
port: this.port,
path: '/jsonrpc',
secure: this.secure,
query: {
method: m.method,
id: m.id,
params: (typeof m.params === 'object' && m.params !== null) ? b64(JSON.stringify(m.params)) : undefined
}
};
httpclient(opts, (function(err, res) {
if (err)
return fn(err);
var m = JSON.parse(res.body.toString());
this._onmessage(m);
}).bind(this));
};
httpclient = require('httpclient');
}
else {
WebSocket = global.WebSocket;
b64 = atob;
http = function(m, fn) {
var jc = 'aria2jsonp' + Date.now();
var protocol = this.secure === true ? 'https' : 'http';
var url = protocol + '://' + this.host + ':' + this.port + '/jsonrpc?jsoncallback=' + jc + '&id=' + m.id + '&method=' + m.method;
if (m.params)
url += '&params=' + b64(JSON.stringify(m.params));
var el = document.createElement('script');
el.src = url;
el.async = true;
global[jc] = (function(m) {
this._onmessage(m);
delete global[jc];
delete el.onerror;
el.parentNode.remove(el);
}).bind(this);
el.onerror = function(e) {
fn(e);
delete el.onerror;
el.parentNode.remove(el);
};
var head = document.head || document.getElementsByTagName('head')[0];
head.appendChild(el);
};
b64 = global.atob;
httpclient = global.HTTPClient;
}

@@ -87,6 +37,34 @@

};
['open', 'close', 'send', 'message'].forEach(function(e) {
Aria2.prototype['on' + e] = function() {};
});
Aria2.prototype.http = http;
Aria2.prototype.http = function(m, fn) {
//FIXME json-rpc post wouldn't work
var opts = {
host: this.host,
port: this.port,
path: '/jsonrpc',
secure: this.secure,
query: {
method: m.method,
id: m.id,
}
};
if (typeof m.params === 'object' && m.params !== null)
opts.query.params = b64(JSON.stringify(m.params));
//browser, use jsonp
if (typeof module === 'undefined')
opts.jsonp = 'jsoncallback';
httpclient(opts, (function(err, res) {
if (err)
return fn(err);
if (opts.jsonp)
return this._onmessage(res.body);
var m = JSON.parse(res.body.toString())
this._onmessage(m);
}).bind(this));
};
Aria2.prototype.send = function(method, params, fn) {

@@ -101,3 +79,3 @@ var m = {

fn = params;
else
else if (typeof m.params === 'object' && m.params !== null)
m.params = params;

@@ -113,8 +91,8 @@

return this.socket.send(JSON.stringify(m));
//send via http
else
this.http(m, (function(err) {
fn(err);
delete this.callbacks[m.id];
}).bind(this));
this.http(m, (function(err) {
fn(err);
delete this.callbacks[m.id];
}).bind(this));
};

@@ -209,2 +187,6 @@ Aria2.prototype._onmessage = function(m) {

['open', 'close', 'send', 'message'].forEach(function(e) {
Aria2.prototype['on' + e] = function() {};
});
if (typeof module !== 'undefined' && module.exports)

@@ -211,0 +193,0 @@ module.exports = Aria2;

@@ -1,1 +0,1 @@

!function(a){"use strict";var b,c,d;if("undefined"!=typeof module&&module.exports){b=require("ws"),c=function(a){return new Buffer(a).toString("base64")};var e=require("httpclient");d=function(a,b){var d={host:this.host,port:this.port,path:"/jsonrpc",secure:this.secure,query:{method:a.method,id:a.id,params:"object"==typeof a.params&&null!==a.params?c(JSON.stringify(a.params)):void 0}};e(d,function(a,c){if(a)return b(a);var d=JSON.parse(c.body.toString());this._onmessage(d)}.bind(this))}}else b=a.WebSocket,c=atob,d=function(b,d){var e="aria2jsonp"+Date.now(),f=this.secure===!0?"https":"http",g=f+"://"+this.host+":"+this.port+"/jsonrpc?jsoncallback="+e+"&id="+b.id+"&method="+b.method;b.params&&(g+="&params="+c(JSON.stringify(b.params)));var h=document.createElement("script");h.src=g,h.async=!0,a[e]=function(b){this._onmessage(b),delete a[e],delete h.onerror,h.parentNode.remove(h)}.bind(this),h.onerror=function(a){d(a),delete h.onerror,h.parentNode.remove(h)};var i=document.head||document.getElementsByTagName("head")[0];i.appendChild(h)};var f={secure:!1,host:"localhost",port:8600},g=function(a){this.callbacks={},this.lastId=0;for(var b in f)this[b]="object"==typeof a&&b in a?a[b]:f[b]};["open","close","send","message"].forEach(function(a){g.prototype["on"+a]=function(){}}),g.prototype.http=d,g.prototype.send=function(a,b,c){var d={method:"aria2."+a,"json-rpc":"2.0",id:this.lastId++};return"function"==typeof b?c=b:d.params=b,c&&(this.callbacks[d.id]=c),this.onsend(d),this.socket&&1===this.socket.readyState?this.socket.send(JSON.stringify(d)):void this.http(d,function(a){c(a),delete this.callbacks[d.id]}.bind(this))},g.prototype._onmessage=function(a){if(void 0!==a.id){var b=this.callbacks[a.id];b&&(a.error?b(a.error):a.result&&b(void 0,a.result),delete this.callbacks[a.id])}else if(a.method){var c=a.method.split("aria2.")[1];c in g.notifications&&this[c](a.params)}this.onmessage(a)},g.prototype.open=function(a){a=a||(this.secure?"wss":"ws")+"://"+this.host+":"+this.port+"/jsonrpc",this.socket=new b(a),this.socket.onopen=this.onopen.bind(this),this.socket.onclose=this.onclose.bind(this),this.socket.onmessage=function(a){this._onmessage(JSON.parse(a.data))}.bind(this)},g.prototype.close=function(){this.socket.close()},g.methods={addUri:{},addTorrent:{},addMetalink:{},remove:{},forceRemove:{},pause:{},pauseAll:{},forcePause:{},forcePauseAll:{},unpause:{},unpauseAll:{},tellStatus:{},getUris:{},getFiles:{},getPeers:{},getServers:{},tellActive:{},tellWaiting:{},tellStopped:{},changePosition:{},changeUri:{},getOption:{},changeOption:{},getGlobalOption:{},changeGlobalOption:{},getGlobalStat:{},purgeDownloadResult:{},removeDownloadResult:{},getVersion:{},getSessionInfo:{},shutdown:{},forceShutdown:{}},g.notifications={onDownloadStart:{},onDownloadPause:{},onDownloadStop:{},onDownloadComplete:{},onDownloadError:{},onBtDownloadComplete:{}};for(var h in g.methods)!function(a){g.prototype[a]=function(){this.send(a,arguments[0],arguments[1])}}(h);for(var i in g.notifications)g.prototype[i]=function(){};"undefined"!=typeof module&&module.exports?module.exports=g:a.Aria2=g}(this);
!function(a){"use strict";var b=function(a,b,c){b=b||"&",c=c||"=";var d="";if("object"==typeof a){for(var e in a)d+=e+c+a[e]+b;d.length>0&&(d="?"+d.slice(0,-1))}return d},c=function(a){var c=b(a.query);return[a.secure?"https":"http","://",a.host,a.port?":"+a.port:"",a.path||"/",c,a.hash||""].join("")},d=a.XMLHttpRequest,e=function(){},f=function(b,d){var e=b.query[b.jsonp],f=c(b),g=document.createElement("script");g.src=f,g.async=!0,a[e]=function(b){d(null,b),delete a[e],delete g.onerror,g.parentNode.remove(g)},g.onerror=function(b){d(b),delete g.onerror,delete a[e],g.parentNode.remove(g)};var h=document.head||document.getElementsByTagName("head")[0];h.appendChild(g)},g=function(a){for(var b=["response","error","end"],g=0;g<b.length;g++)this["on"+b[g]]=e;var h=HTTPClient.utils.handleOptions(a);for(var i in h)this[i]=h[i];if("string"==typeof h.jsonp)return void f(h,function(a,b){a?this.onerror(a):this.onend(b)}.bind(this));var j=new d;j.addEventListener("error",function(a){this.onerror(a)}.bind(this)),j.addEventListener("readystatechange",function(){if(2===j.readyState){var a={},b=j.getAllResponseHeaders();if(b)for(var c=b.split("\n"),d=0;d<c.length;d++)if(c[d]){var e=c[d].split(":");a[e[0].toLowerCase()]=e.slice(1).join().trim()}var f=j.status;this.onresponse({headers:a,status:f,type:HTTPClient.utils.getTypeFromHeaders(a)})}else 4===j.readyState&&this.onend(j.response)}.bind(this)),j.open(h.method,c(h),!0);for(var k in h.headers)j.setRequestHeader(k,h.headers[k]);j.send(h.body),this.req=j};g.prototype.abort=function(){this.req.abort()},a.HTTPRequest=g}(this),function(a){"use strict";var b;b="undefined"!=typeof module&&module.exports?require("./lib/node"):a.HTTPRequest;var c=function(a,c){if(!c)return new b(a);var d=new b(a);d.onerror=function(a){c(a)};var e;return d.onresponse=function(a){e=a},d.onend=function(a){e=e||{},e.body=a,c(null,e)},d};"undefined"!=typeof module&&module.exports?module.exports=c:a.HTTPClient=c}(this),function(a){"use strict";var b;b="undefined"!=typeof Buffer?function(a){return new Buffer(a).toString("base64")}:a.btoa;var c=function(a){return Object.getPrototypeOf?Object.getPrototypeOf(a):a.__proto__},d=c({}),e=function(a){return"object"!=typeof a?!1:c(a)===d||null===c(a)},f=function(a){var c={};c.query="object"==typeof a.query?a.query:{},c.secure=!!a.secure||!1,c.port=a.port||(c.secure?443:80),c.host=a.host||"localhost",c.path=a.path||"/",c.headers="object"==typeof a.headers?a.headers:{},c.method="string"==typeof a.method?a.method.toUpperCase():"GET",a.jsonp===!0&&(a.jsonp="callback"),"string"==typeof a.jsonp&&(c.jsonp=a.jsonp,c.query[a.jsonp]="HTTPClient"+Date.now());for(var d in c.headers){var f=c.headers[d];delete c.headers[d],c.headers[d.toLowerCase()]=f}if("string"==typeof a.username&&"string"==typeof a.password){var g=a.username+":"+a.password;c.headers.authorization="Basic "+b(g)}return Array.isArray(a.body)||e(a.body)?(c.body=JSON.stringify(a.body),c.headers["tontent-type"]||(c.headers["content-type"]="application/json; charset=utf-8")):"string"==typeof a.body?(c.body=a.body,c.headers["content-type"]||(c.headers["content-type"]="text/plain; charset=utf-8")):(void 0!==a.body||null!==a.body)&&(c.body=a.body),c},g=function(a){var b="";if("object"==typeof a){var c=a["content-type"];c&&(b=c.split(";")[0])}return b},h={handleOptions:f,getTypeFromHeaders:g,getPrototypeOf:c};"undefined"!=typeof module&&module.exports?module.exports=h:a.HTTPClient.utils=h}(this),function(a){"use strict";var b,c,d;"undefined"!=typeof module&&module.exports?(b=require("ws"),c=function(a){return new Buffer(a).toString("base64")},d=require("httpclient")):(b=a.WebSocket,c=a.atob,d=a.HTTPClient);var e={secure:!1,host:"localhost",port:8600},f=function(a){this.callbacks={},this.lastId=0;for(var b in e)this[b]="object"==typeof a&&b in a?a[b]:e[b]};f.prototype.http=function(a,b){var e={host:this.host,port:this.port,path:"/jsonrpc",secure:this.secure,query:{method:a.method,id:a.id}};"object"==typeof a.params&&null!==a.params&&(e.query.params=c(JSON.stringify(a.params))),"undefined"==typeof module&&(e.jsonp="jsoncallback"),d(e,function(a,c){if(a)return b(a);if(e.jsonp)return this._onmessage(c.body);var d=JSON.parse(c.body.toString());this._onmessage(d)}.bind(this))},f.prototype.send=function(a,b,c){var d={method:"aria2."+a,"json-rpc":"2.0",id:this.lastId++};return"function"==typeof b?c=b:"object"==typeof d.params&&null!==d.params&&(d.params=b),c&&(this.callbacks[d.id]=c),this.onsend(d),this.socket&&1===this.socket.readyState?this.socket.send(JSON.stringify(d)):void this.http(d,function(a){c(a),delete this.callbacks[d.id]}.bind(this))},f.prototype._onmessage=function(a){if(void 0!==a.id){var b=this.callbacks[a.id];b&&(a.error?b(a.error):a.result&&b(void 0,a.result),delete this.callbacks[a.id])}else if(a.method){var c=a.method.split("aria2.")[1];c in f.notifications&&this[c](a.params)}this.onmessage(a)},f.prototype.open=function(a){a=a||(this.secure?"wss":"ws")+"://"+this.host+":"+this.port+"/jsonrpc",this.socket=new b(a),this.socket.onopen=this.onopen.bind(this),this.socket.onclose=this.onclose.bind(this),this.socket.onmessage=function(a){this._onmessage(JSON.parse(a.data))}.bind(this)},f.prototype.close=function(){this.socket.close()},f.methods={addUri:{},addTorrent:{},addMetalink:{},remove:{},forceRemove:{},pause:{},pauseAll:{},forcePause:{},forcePauseAll:{},unpause:{},unpauseAll:{},tellStatus:{},getUris:{},getFiles:{},getPeers:{},getServers:{},tellActive:{},tellWaiting:{},tellStopped:{},changePosition:{},changeUri:{},getOption:{},changeOption:{},getGlobalOption:{},changeGlobalOption:{},getGlobalStat:{},purgeDownloadResult:{},removeDownloadResult:{},getVersion:{},getSessionInfo:{},shutdown:{},forceShutdown:{}},f.notifications={onDownloadStart:{},onDownloadPause:{},onDownloadStop:{},onDownloadComplete:{},onDownloadError:{},onBtDownloadComplete:{}};for(var g in f.methods)!function(a){f.prototype[a]=function(){this.send(a,arguments[0],arguments[1])}}(g);for(var h in f.notifications)f.prototype[h]=function(){};["open","close","send","message"].forEach(function(a){f.prototype["on"+a]=function(){}}),"undefined"!=typeof module&&module.exports?module.exports=f:a.Aria2=f}(this);

@@ -7,3 +7,3 @@ (function(global) {

var b64;
var http;
var httpclient;;
if (typeof module !== 'undefined' && module.exports) {

@@ -14,59 +14,8 @@ WebSocket = require('ws');

};
var httpclient = require('httpclient');
http = function(m, fn) {
//FIXME json-rpc post won't work
var opts = {
host: this.host,
port: this.port,
path: '/jsonrpc',
secure: this.secure,
query: {
method: m.method,
id: m.id,
params: (typeof m.params === 'object' && m.params !== null) ? b64(JSON.stringify(m.params)) : undefined
}
};
httpclient(opts, (function(err, res) {
if (err)
return fn(err);
var m = JSON.parse(res.body.toString());
this._onmessage(m);
}).bind(this));
};
httpclient = require('httpclient');
}
else {
WebSocket = global.WebSocket;
b64 = atob;
http = function(m, fn) {
var jc = 'aria2jsonp' + Date.now();
var protocol = this.secure === true ? 'https' : 'http';
var url = protocol + '://' + this.host + ':' + this.port + '/jsonrpc?jsoncallback=' + jc + '&id=' + m.id + '&method=' + m.method;
if (m.params)
url += '&params=' + b64(JSON.stringify(m.params));
var el = document.createElement('script');
el.src = url;
el.async = true;
global[jc] = (function(m) {
this._onmessage(m);
delete global[jc];
delete el.onerror;
el.parentNode.remove(el);
}).bind(this);
el.onerror = function(e) {
fn(e);
delete el.onerror;
el.parentNode.remove(el);
};
var head = document.head || document.getElementsByTagName('head')[0];
head.appendChild(el);
};
b64 = global.atob;
httpclient = global.HTTPClient;
}

@@ -87,6 +36,34 @@

};
['open', 'close', 'send', 'message'].forEach(function(e) {
Aria2.prototype['on' + e] = function() {};
});
Aria2.prototype.http = http;
Aria2.prototype.http = function(m, fn) {
//FIXME json-rpc post wouldn't work
var opts = {
host: this.host,
port: this.port,
path: '/jsonrpc',
secure: this.secure,
query: {
method: m.method,
id: m.id,
}
};
if (typeof m.params === 'object' && m.params !== null)
opts.query.params = b64(JSON.stringify(m.params));
//browser, use jsonp
if (typeof module === 'undefined')
opts.jsonp = 'jsoncallback';
httpclient(opts, (function(err, res) {
if (err)
return fn(err);
if (opts.jsonp)
return this._onmessage(res.body);
var m = JSON.parse(res.body.toString())
this._onmessage(m);
}).bind(this));
};
Aria2.prototype.send = function(method, params, fn) {

@@ -101,3 +78,3 @@ var m = {

fn = params;
else
else if (typeof m.params === 'object' && m.params !== null)
m.params = params;

@@ -113,8 +90,8 @@

return this.socket.send(JSON.stringify(m));
//send via http
else
this.http(m, (function(err) {
fn(err);
delete this.callbacks[m.id];
}).bind(this));
this.http(m, (function(err) {
fn(err);
delete this.callbacks[m.id];
}).bind(this));
};

@@ -209,2 +186,6 @@ Aria2.prototype._onmessage = function(m) {

['open', 'close', 'send', 'message'].forEach(function(e) {
Aria2.prototype['on' + e] = function() {};
});
if (typeof module !== 'undefined' && module.exports)

@@ -211,0 +192,0 @@ module.exports = Aria2;

{
"name": "aria2",
"version": "0.0.2",
"version": "0.0.3",
"description": "Library for aria2, \"The next generation download utility.\"",

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

"ws": "~0.4.31",
"httpclient": "0.0.1",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-uglify": "~0.3.2"
"httpclient": "~0.0.3"
},

@@ -37,4 +35,5 @@ "devDependencies": {

"grunt-contrib-jshint": "~0.8.0",
"grunt-mocha-test": "~0.9.0"
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-uglify": "~0.3.2"
}
}

@@ -6,3 +6,2 @@ aria2.js

[![Build Status](https://travis-ci.org/sonnyp/aria2.js.png?branch=master)](https://travis-ci.org/sonnyp/aria2.js)

@@ -17,3 +16,3 @@

### Browsers
### Browser
```

@@ -23,3 +22,3 @@ bower install aria2

```xml
<script src="aria2.js/lib/index.js"></script>
<script src="bower_components/aria2/aria2.min.js"></script>
```

@@ -31,6 +30,19 @@

```
```
```javascript
var aria2 = require('aria2');
```
## Init
```javascript
var aria2 = new Aria2([options]);
```
default and only valid options are
```javascript
{
host: 'localhost',
port: 6800,
secure: false
}
```
## Open

@@ -37,0 +49,0 @@

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