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
This commit is contained in:
Ryan X. Charles 2014-09-22 17:09:53 -07:00
parent 792e8080c8
commit 9b8ce05b15
2 changed files with 15 additions and 0 deletions

View File

@ -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);
};

View File

@ -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() {