11module . exports = Client
22
3+ var Buffer = require ( 'safe-buffer' ) . Buffer
34var debug = require ( 'debug' ) ( 'bittorrent-tracker' )
45var EventEmitter = require ( 'events' ) . EventEmitter
56var extend = require ( 'xtend' )
@@ -46,13 +47,13 @@ function Client (opts) {
4647 self . peerId = typeof opts . peerId === 'string'
4748 ? opts . peerId
4849 : opts . peerId . toString ( 'hex' )
49- self . _peerIdBuffer = new Buffer ( self . peerId , 'hex' )
50+ self . _peerIdBuffer = Buffer . from ( self . peerId , 'hex' )
5051 self . _peerIdBinary = self . _peerIdBuffer . toString ( 'binary' )
5152
5253 self . infoHash = typeof opts . infoHash === 'string'
5354 ? opts . infoHash
5455 : opts . infoHash . toString ( 'hex' )
55- self . _infoHashBuffer = new Buffer ( self . infoHash , 'hex' )
56+ self . _infoHashBuffer = Buffer . from ( self . infoHash , 'hex' )
5657 self . _infoHashBinary = self . _infoHashBuffer . toString ( 'binary' )
5758
5859 self . _port = opts . port
@@ -131,7 +132,7 @@ Client.scrape = function (opts, cb) {
131132
132133 var clientOpts = extend ( opts , {
133134 infoHash : Array . isArray ( opts . infoHash ) ? opts . infoHash [ 0 ] : opts . infoHash ,
134- peerId : new Buffer ( '01234567890123456789' ) , // dummy value
135+ peerId : Buffer . from ( '01234567890123456789' ) , // dummy value
135136 port : 6881 // dummy value
136137 } )
137138
@@ -156,9 +157,9 @@ Client.scrape = function (opts, cb) {
156157
157158 opts . infoHash = Array . isArray ( opts . infoHash )
158159 ? opts . infoHash . map ( function ( infoHash ) {
159- return new Buffer ( String ( infoHash ) , 'hex' )
160+ return Buffer . from ( infoHash , 'hex' )
160161 } )
161- : new Buffer ( String ( opts . infoHash ) , 'hex' )
162+ : Buffer . from ( opts . infoHash , 'hex' )
162163 client . scrape ( { infoHash : opts . infoHash } )
163164 return client
164165}
0 commit comments