BufferList.concat

This commit is contained in:
brianc 2010-09-29 02:39:43 -05:00
parent 871f529fea
commit bf03dbf3f8
2 changed files with 17 additions and 1 deletions

View File

@ -34,7 +34,8 @@ stringToHex = function(string) {
hexToString = function(hexArray) {
return new Buffer(hexArray).toString('utf8');
}
var BufferList = function() {
BufferList = function() {
this.buffers = [];
};
@ -84,3 +85,11 @@ BufferList.prototype.join = function(appendLength, char) {
});
return result;
};
BufferList.concat = function() {
var total = new BufferList();
for(var i = 0; i < arguments.length; i++) {
total.add(arguments[i]);
}
return total.join();
};

View File

@ -63,3 +63,10 @@ test('does complicated buffer', function() {
.join(true,'!');
assert.equalBuffers(buf, [33, 0, 0, 0, 0x0c, 0, 0, 0, 1, 0, 2, 33, 0]);
});
test('concats', function() {
var buf1 = new BufferList().addInt32(8).join(false,'!');
var buf2 = new BufferList().addInt16(1).join();
var result = BufferList.concat(buf1, buf2);
assert.equalBuffers(result, [33, 0, 0, 0, 8, 0, 1]);
});