mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2025-01-18 20:21:36 +00:00
use bn.js instead of bignum
This commit is contained in:
parent
44bb19c8c9
commit
64eaa3f936
21
index.js
21
index.js
@ -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) {
|
||||||
|
@ -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",
|
||||||
|
Loading…
Reference in New Issue
Block a user