diff --git a/lib/bencoding.js b/lib/bencoding.js index cd8a122..79354b1 100644 --- a/lib/bencoding.js +++ b/lib/bencoding.js @@ -19,7 +19,16 @@ BDict.prototype.add = function (key, val) { this.keys.push(key); this.vals.push(val); this.length++; + return this; }; + +BDict.prototype.remove = function (i) { + this.keys.splice(i, 1); + this.vals.splice(i, 1); + this.length--; + return this; +}; + BDict.prototype.vget = function (i) { return this.vals[i]; }; @@ -27,7 +36,7 @@ BDict.prototype.kget = function (i) { return this.keys[i]; } BDict.prototype.get = function (i) { - return [this.keys[i], this.vals[i]]; + return this.keys[i] && this.vals[i] ? [this.keys[i], this.vals[i]] : undefined; }; BDict.prototype.toJSON = function () { var ret = {}; @@ -170,3 +179,4 @@ function encode(obj) { exports = module.exports; exports.decode = decode; exports.encode = encode; +exports.BDict = BDict;