mirror of
https://github.com/brianc/node-postgres.git
synced 2026-01-25 16:03:13 +00:00
shortcut the join method for single buffer writers
This commit is contained in:
parent
51d922f3e1
commit
66add6defc
@ -17,9 +17,12 @@ p.addInt16 = function(val, front) {
|
||||
};
|
||||
|
||||
p.getByteLength = function(initial) {
|
||||
return this.buffers.reduce(function(previous, current){
|
||||
return previous + current.length;
|
||||
},initial || 0);
|
||||
var totalBufferLength = 0;
|
||||
var buffers = this.buffers;
|
||||
for(var i = 0, len = buffers.length; i < len; i++) {
|
||||
totalBufferLength += buffers[i].length;
|
||||
}
|
||||
return totalBufferLength;
|
||||
};
|
||||
|
||||
p.addInt32 = function(val, first) {
|
||||
@ -44,10 +47,13 @@ p.addChar = function(char, first) {
|
||||
};
|
||||
|
||||
p.join = function() {
|
||||
var length = this.buffers.length;
|
||||
if(length===1) {
|
||||
return this.buffers[0]
|
||||
}
|
||||
var result = Buffer(this.getByteLength());
|
||||
var index = 0;
|
||||
var buffers = this.buffers;
|
||||
var length = this.buffers.length;
|
||||
for(var i = 0; i < length; i ++) {
|
||||
var buffer = buffers[i];
|
||||
buffer.copy(result, index, 0);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user