From e80785654c0476b5b01f68d95985f0281d68dbe8 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 3 Jul 2016 14:00:44 -0700 Subject: [PATCH] minor. --- lib/bcoin/rbt.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/bcoin/rbt.js b/lib/bcoin/rbt.js index 709f68cd..44257b55 100644 --- a/lib/bcoin/rbt.js +++ b/lib/bcoin/rbt.js @@ -29,6 +29,11 @@ function RBT(location, options) { if (!(this instanceof RBT)) return new RBT(location, options); + if (typeof location !== 'string') { + options = location; + location = null; + } + if (!options) options = {}; @@ -804,7 +809,7 @@ RBTNode.prototype.copy = function copy() { RBTNode.prototype.inspect = function inspect() { return { - key: this.key.toString('ascii'), + key: stringify(this.key), value: this.value.toString('hex'), color: this.color === RED ? 'red' : 'black', left: this.left, @@ -882,7 +887,7 @@ function RBTData(key, value) { RBTData.prototype.inspect = function inspect() { return { - key: this.key.toString('ascii'), + key: stringify(this.key), value: this.value.toString('hex') }; }; @@ -1051,7 +1056,7 @@ Iterator.prototype.next = function(callback) { value = DUMMY; if (this.options.keyAsBuffer === false) - key = key.toString('ascii'); + key = stringify(key); if (this.options.valueAsBuffer === false) value = value.toString('utf8'); @@ -1112,6 +1117,12 @@ Iterator.prototype.end = function end(callback) { SENTINEL = new RBTSentinel(); +function stringify(value) { + if (Buffer.isBuffer(value)) + return value.toString('ascii'); + return value; +} + /* * Expose */