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:
parent
792e8080c8
commit
9b8ce05b15
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -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…
Reference in New Issue