Browse Source

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
patch-2
Ryan X. Charles 10 years ago
parent
commit
9b8ce05b15
  1. 4
      lib/bufferwriter.js
  2. 11
      test/bufferwriter.js

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

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

Loading…
Cancel
Save