use bn.js instead of bignum

This commit is contained in:
Mathias Buus 2014-04-30 23:02:19 +02:00
parent 44bb19c8c9
commit 64eaa3f936
2 changed files with 8 additions and 19 deletions

View File

@ -1,12 +1,7 @@
exports.Client = Client exports.Client = Client
exports.Server = Server exports.Server = Server
// optional compiled dependency. if it doesn't compile, no big deal. var bn = require('bn.js')
var bignum
try {
bignum = require('bignum')
} catch (e) {}
var bncode = require('bncode') var bncode = require('bncode')
var compact2string = require('compact2string') var compact2string = require('compact2string')
var dgram = require('dgram') var dgram = require('dgram')
@ -528,16 +523,12 @@ function toUInt32 (n) {
} }
function toUInt64 (n) { function toUInt64 (n) {
if (typeof bignum === 'function') { if (n > MAX_UINT || typeof n === 'string') {
return bignum(n).toBuffer({ size: 8 }) var bytes = bn(n).toArray()
} else { while (bytes.length < 8) bytes.unshift(0)
// optional compiled dependency 'bignum' is not available, so round down to MAX_UINT. return new Buffer(bytes)
// These values are only used for tracker stats anyway.
if (n > MAX_UINT) {
n = MAX_UINT
}
return Buffer.concat([toUInt32(0), toUInt32(n)])
} }
return Buffer.concat([toUInt32(0), toUInt32(n)])
} }
function bytewiseEncodeURIComponent (buf) { function bytewiseEncodeURIComponent (buf) {

View File

@ -18,16 +18,14 @@
"inherits": "^2.0.1", "inherits": "^2.0.1",
"querystring": "^0.2.0", "querystring": "^0.2.0",
"run-parallel": "^0.3.0", "run-parallel": "^0.3.0",
"string2compact": "^1.1.0" "string2compact": "^1.1.0",
"bn.js": "^0.2.0"
}, },
"devDependencies": { "devDependencies": {
"parse-torrent": "^0.9.0", "parse-torrent": "^0.9.0",
"portfinder": "^0.2.1", "portfinder": "^0.2.1",
"tape": "2.x" "tape": "2.x"
}, },
"optionalDependencies": {
"bignum": "^0.6.2"
},
"homepage": "http://webtorrent.io", "homepage": "http://webtorrent.io",
"keywords": [ "keywords": [
"torrent", "torrent",