Skip to content

Commit cdd1226

Browse files
committed
Merge branch 'mafintosh-bn.js'
2 parents 44bb19c + 64eaa3f commit cdd1226

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

index.js

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
exports.Client = Client
22
exports.Server = Server
33

4-
// optional compiled dependency. if it doesn't compile, no big deal.
5-
var bignum
6-
try {
7-
bignum = require('bignum')
8-
} catch (e) {}
9-
4+
var bn = require('bn.js')
105
var bncode = require('bncode')
116
var compact2string = require('compact2string')
127
var dgram = require('dgram')
@@ -528,16 +523,12 @@ function toUInt32 (n) {
528523
}
529524

530525
function toUInt64 (n) {
531-
if (typeof bignum === 'function') {
532-
return bignum(n).toBuffer({ size: 8 })
533-
} else {
534-
// optional compiled dependency 'bignum' is not available, so round down to MAX_UINT.
535-
// These values are only used for tracker stats anyway.
536-
if (n > MAX_UINT) {
537-
n = MAX_UINT
538-
}
539-
return Buffer.concat([toUInt32(0), toUInt32(n)])
526+
if (n > MAX_UINT || typeof n === 'string') {
527+
var bytes = bn(n).toArray()
528+
while (bytes.length < 8) bytes.unshift(0)
529+
return new Buffer(bytes)
540530
}
531+
return Buffer.concat([toUInt32(0), toUInt32(n)])
541532
}
542533

543534
function bytewiseEncodeURIComponent (buf) {

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,14 @@
1818
"inherits": "^2.0.1",
1919
"querystring": "^0.2.0",
2020
"run-parallel": "^0.3.0",
21-
"string2compact": "^1.1.0"
21+
"string2compact": "^1.1.0",
22+
"bn.js": "^0.2.0"
2223
},
2324
"devDependencies": {
2425
"parse-torrent": "^0.9.0",
2526
"portfinder": "^0.2.1",
2627
"tape": "2.x"
2728
},
28-
"optionalDependencies": {
29-
"bignum": "^0.6.2"
30-
},
3129
"homepage": "http://webtorrent.io",
3230
"keywords": [
3331
"torrent",

0 commit comments

Comments
 (0)