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.Server = Server
|
||||
|
||||
// optional compiled dependency. if it doesn't compile, no big deal.
|
||||
var bignum
|
||||
try {
|
||||
bignum = require('bignum')
|
||||
} catch (e) {}
|
||||
|
||||
var bn = require('bn.js')
|
||||
var bncode = require('bncode')
|
||||
var compact2string = require('compact2string')
|
||||
var dgram = require('dgram')
|
||||
@ -528,16 +523,12 @@ function toUInt32 (n) {
|
||||
}
|
||||
|
||||
function toUInt64 (n) {
|
||||
if (typeof bignum === 'function') {
|
||||
return bignum(n).toBuffer({ size: 8 })
|
||||
} else {
|
||||
// optional compiled dependency 'bignum' is not available, so round down to MAX_UINT.
|
||||
// These values are only used for tracker stats anyway.
|
||||
if (n > MAX_UINT) {
|
||||
n = MAX_UINT
|
||||
}
|
||||
return Buffer.concat([toUInt32(0), toUInt32(n)])
|
||||
if (n > MAX_UINT || typeof n === 'string') {
|
||||
var bytes = bn(n).toArray()
|
||||
while (bytes.length < 8) bytes.unshift(0)
|
||||
return new Buffer(bytes)
|
||||
}
|
||||
return Buffer.concat([toUInt32(0), toUInt32(n)])
|
||||
}
|
||||
|
||||
function bytewiseEncodeURIComponent (buf) {
|
||||
|
@ -18,16 +18,14 @@
|
||||
"inherits": "^2.0.1",
|
||||
"querystring": "^0.2.0",
|
||||
"run-parallel": "^0.3.0",
|
||||
"string2compact": "^1.1.0"
|
||||
"string2compact": "^1.1.0",
|
||||
"bn.js": "^0.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"parse-torrent": "^0.9.0",
|
||||
"portfinder": "^0.2.1",
|
||||
"tape": "2.x"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"bignum": "^0.6.2"
|
||||
},
|
||||
"homepage": "http://webtorrent.io",
|
||||
"keywords": [
|
||||
"torrent",
|
||||
|
Loading…
Reference in New Issue
Block a user