From 9b8ce05b151f691c619c46505653c08acd3341bc Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Mon, 22 Sep 2014 17:09:53 -0700 Subject: [PATCH] BufferWriter().toBuffer convenience method It does the same thing as .concat(), but may be easier to remember, since the rest of the library uses the ".toBuffer()" convention --- lib/bufferwriter.js | 4 ++++ test/bufferwriter.js | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/bufferwriter.js b/lib/bufferwriter.js index fa8e8cd..a61ff90 100644 --- a/lib/bufferwriter.js +++ b/lib/bufferwriter.js @@ -14,6 +14,10 @@ BufferWriter.prototype.set = function(obj) { return this; }; +BufferWriter.prototype.toBuffer = function() { + return this.concat(); +}; + BufferWriter.prototype.concat = function() { return Buffer.concat(this.bufs); }; diff --git a/test/bufferwriter.js b/test/bufferwriter.js index 7042533..fa4b2b9 100644 --- a/test/bufferwriter.js +++ b/test/bufferwriter.js @@ -22,6 +22,17 @@ describe('BufferWriter', function() { }); + describe('#toBuffer', function() { + + it('should concat these two bufs', function() { + var buf1 = new Buffer([0]); + var buf2 = new Buffer([1]); + var bw = new BufferWriter({bufs: [buf1, buf2]}); + bw.toBuffer().toString('hex').should.equal('0001'); + }); + + }); + describe('#concat', function() { it('should concat these two bufs', function() {