Skip to content

Commit c887bf9

Browse files
committed
Merge pull request #24 from deoxxa/binary-keys
binary keys
2 parents 50c859f + f295cfe commit c887bf9

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/decode.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
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++

lib/dict.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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 this._keys.slice()
10+
}
11+
12+
Dict.prototype.binarySet = function binarySet(key, value) {
13+
this._keys.push(key)
14+
15+
this[key] = value
16+
}

0 commit comments

Comments
 (0)