File tree Expand file tree Collapse file tree 2 files changed +8
-19
lines changed
Expand file tree Collapse file tree 2 files changed +8
-19
lines changed Original file line number Diff line number Diff line change 11exports . Client = Client
22exports . 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' )
105var bncode = require ( 'bncode' )
116var compact2string = require ( 'compact2string' )
127var dgram = require ( 'dgram' )
@@ -528,16 +523,12 @@ function toUInt32 (n) {
528523}
529524
530525function 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
543534function bytewiseEncodeURIComponent ( buf ) {
Original file line number Diff line number Diff line change 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" ,
You can’t perform that action at this time.
0 commit comments