From da8989b64943cc6323bd4c594263e104bdda7ff0 Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Thu, 28 Aug 2014 15:27:58 -0700 Subject: [PATCH] add set function to Base58 --- lib/base58.js | 12 +++++++++--- test/test.base58.js | 12 ++++++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/base58.js b/lib/base58.js index 1bb24f82b..da977ca3c 100644 --- a/lib/base58.js +++ b/lib/base58.js @@ -1,9 +1,15 @@ var bs58 = require('bs58'); -var Base58 = function Base58(buf) { +var Base58 = function Base58(obj) { if (!(this instanceof Base58)) - return new Base58(buf); - this.buf = buf; + return new Base58(obj); + if (obj) + this.set(obj); +}; + +Base58.prototype.set = function(obj) { + this.buf = obj.buf || this.buf || undefined; + return this; }; Base58.encode = function(buf) { diff --git a/test/test.base58.js b/test/test.base58.js index 236f5d03e..fca7d9a32 100644 --- a/test/test.base58.js +++ b/test/test.base58.js @@ -15,6 +15,14 @@ describe('Base58', function() { should.exist(b58); }); + describe('#set', function() { + + it('should set a blank buffer', function() { + Base58().set({buf: new Buffer([])}); + }); + + }); + describe('@encode', function() { it('should encode the buffer accurately', function() { @@ -67,7 +75,7 @@ describe('Base58', function() { describe('#toBuffer', function() { it('should return the buffer', function() { - var b58 = Base58(buf); + var b58 = Base58({buf: buf}); b58.buf.toString('hex').should.equal(buf.toString('hex')); }); @@ -76,7 +84,7 @@ describe('Base58', function() { describe('#toString', function() { it('should return the buffer', function() { - var b58 = Base58(buf); + var b58 = Base58({buf: buf}); b58.toString().should.equal(enc); });