Skip to content

Commit c325767

Browse files
committed
Updated bencode.js: Streamlined the multibyte fix
1 parent 3e2ed23 commit c325767

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

bencode.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
*/
88
function encode( data ) {
99

10-
if( Buffer.isBuffer( data ) )
11-
return encode.bytes( data )
10+
if( data instanceof Buffer )
11+
return data.length + ':' + data
1212

1313
switch( typeof data ) {
1414
case 'string':
@@ -27,8 +27,6 @@ function encode( data ) {
2727
}
2828

2929
encode.bytes = function( data ) {
30-
if( data instanceof Buffer )
31-
return data.length + ':' + data
3230
return Buffer.byteLength( data ) + ':' + data
3331
}
3432

0 commit comments

Comments
 (0)