File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed
Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -43,8 +43,12 @@ encode.bytes = function( buffers, data ) {
4343}
4444
4545encode . number = function ( buffers , data ) {
46+ var maxLo = 4294967295
47+ var hi = ( data / maxLo ) << 0
48+ var lo = ( data % maxLo ) << 0
49+ var val = hi * maxLo + lo
4650 buffers . push (
47- new Buffer ( 'i' + ( data << 0 ) + 'e'
51+ new Buffer ( 'i' + val + 'e'
4852 ) )
4953}
5054
Original file line number Diff line number Diff line change @@ -36,6 +36,18 @@ describe("bencode", function() {
3636 it ( 'should be able to encode a negative float (as int)' , function ( ) {
3737 assert . equal ( bencode . encode ( - 123.5 ) , 'i-123e' ) ;
3838 } )
39+ it ( 'should be able to encode a positive 64 bit int' , function ( ) {
40+ assert . equal ( bencode . encode ( 4777722361 ) , 'i4777722361e' ) ;
41+ } )
42+ it ( 'should be able to encode a negative 64 bit int' , function ( ) {
43+ assert . equal ( bencode . encode ( - 4777722361 ) , 'i-4777722361e' ) ;
44+ } )
45+ it ( 'should be able to encode a positive 64 bit float (as int)' , function ( ) {
46+ assert . equal ( bencode . encode ( 4777722361.5 ) , 'i4777722361e' ) ;
47+ } )
48+ it ( 'should be able to encode a negative 64 bit float (as int)' , function ( ) {
49+ assert . equal ( bencode . encode ( - 4777722361.5 ) , 'i-4777722361e' ) ;
50+ } )
3951 it ( 'should be able to encode a string' , function ( ) {
4052 assert . equal ( bencode . encode ( "asdf" ) , '4:asdf' ) ;
4153 assert . equal ( bencode . encode ( ":asdf:" ) , '6::asdf:' ) ;
You can’t perform that action at this time.
0 commit comments