writer's buffer resize no longer dies when item byteLength > 2x buffer length
This commit is contained in:
parent
f5fce3542b
commit
3500154d2a
@ -10,16 +10,12 @@ p._remaining = function() {
|
||||
return this.buffer.length - this.offset;
|
||||
}
|
||||
|
||||
p._resize = function() {
|
||||
var oldBuffer = this.buffer;
|
||||
this.buffer = Buffer(oldBuffer.length + this.size);
|
||||
oldBuffer.copy(this.buffer);
|
||||
}
|
||||
|
||||
//resizes internal buffer if not enough size left
|
||||
p._ensure = function(size) {
|
||||
if(this._remaining() < size) {
|
||||
this._resize()
|
||||
var oldBuffer = this.buffer;
|
||||
this.buffer = Buffer(oldBuffer.length + size);
|
||||
oldBuffer.copy(this.buffer);
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,7 +42,7 @@ p.addCString = function(string) {
|
||||
this.buffer.write(string, this.offset);
|
||||
this.offset += len;
|
||||
this.buffer[this.offset] = 0; //add null terminator
|
||||
return this;
|
||||
return this;
|
||||
}
|
||||
|
||||
p.addChar = function(char) {
|
||||
|
@ -149,5 +149,9 @@ test('clearing', function() {
|
||||
|
||||
})
|
||||
|
||||
|
||||
|
||||
test("resizing to much larger", function() {
|
||||
var subject = new Writer(2);
|
||||
var string = "!!!!!!!!";
|
||||
var result = subject.addCString(string).flush();
|
||||
assert.equalBuffers(result, [33, 33, 33, 33, 33, 33, 33, 33, 0])
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user