mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
Writer#flush
This commit is contained in:
parent
222fbffcfd
commit
99086cf4bf
@ -75,4 +75,10 @@ p.clear = function() {
|
||||
this.offset=0;
|
||||
}
|
||||
|
||||
p.flush = function() {
|
||||
var result = this.join();
|
||||
this.clear();
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = Writer;
|
||||
|
||||
@ -78,7 +78,7 @@ test('cString', function() {
|
||||
var result = subject.addCString("!!!").join();
|
||||
assert.equalBuffers(result, [33, 33, 33, 0]);
|
||||
})
|
||||
|
||||
|
||||
test('writes multiple cstrings', function() {
|
||||
var subject = new Writer();
|
||||
var result = subject.addCString("!").addCString("!").join();
|
||||
@ -115,4 +115,22 @@ test('clearing', function() {
|
||||
subject.addInt32(10401);
|
||||
subject.clear();
|
||||
assert.equalBuffers(subject.join(), []);
|
||||
test('can keep writing', function() {
|
||||
var joinedResult = subject.addCString("!").addInt32(9).addInt16(2).join();
|
||||
assert.equalBuffers(joinedResult, [33, 0, 0, 0, 0, 9, 0, 2]);
|
||||
test('flush', function() {
|
||||
var flushedResult = subject.flush();
|
||||
test('returns result', function() {
|
||||
assert.equalBuffers(flushedResult, [33, 0, 0, 0, 0, 9, 0, 2])
|
||||
})
|
||||
test('clears the writer', function() {
|
||||
assert.equalBuffers(subject.join(), [])
|
||||
assert.equalBuffers(subject.flush(), [])
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user