File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed
Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change 1+ var Dict = require ( "./dict" )
2+
13/**
24 * Decodes bencoded data.
35 *
@@ -57,10 +59,10 @@ decode.dictionary = function() {
5759
5860 decode . position ++
5961
60- var dict = { }
62+ var dict = new Dict ( )
6163
6264 while ( decode . data [ decode . position ] !== 0x65 ) {
63- dict [ decode . bytes ( ) ] = decode . next ( )
65+ dict . binarySet ( decode . bytes ( ) , decode . next ( ) )
6466 }
6567
6668 decode . position ++
Original file line number Diff line number Diff line change 1+ var Dict = module . exports = function Dict ( ) {
2+ Object . defineProperty ( this , "_keys" , {
3+ enumerable : false ,
4+ value : { } ,
5+ } )
6+ }
7+
8+ Dict . prototype . binaryKeys = function binaryKeys ( ) {
9+ return Object . keys ( this . _keys ) . map ( function ( e ) {
10+ return Buffer ( e , "hex" )
11+ } )
12+ }
13+
14+ Dict . prototype . binaryGet = function binaryGet ( key ) {
15+ key = key . toString ( "hex" )
16+
17+ return this . _keys [ key ] && this [ this . _keys [ key ] ]
18+ }
19+
20+ Dict . prototype . binarySet = function binarySet ( key , value ) {
21+ this . _keys [ key . toString ( "hex" ) ] = key . toString ( )
22+
23+ this [ key ] = value
24+ }
You can’t perform that action at this time.
0 commit comments