Skip to content

Commit bd8af71

Browse files
committed
Allow providing initial buffer
1 parent d1f08cb commit bd8af71

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

buffer-builder.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
module.exports = BufferBuilder;
22

33
function BufferBuilder(initialCapacity) {
4-
initialCapacity = Math.max(1, initialCapacity || 512);
5-
this.buffers = [new Buffer(initialCapacity)];
4+
var buffer = Buffer.isBuffer(initialCapacity) ? initialCapacity : new Buffer(initialCapacity || 512);
5+
this.buffers = [buffer];
6+
67
this.writeIndex = 0;
78
this.length = 0;
8-
};
9+
}
910

1011
/* Append a (subsequence of a) Buffer */
1112
BufferBuilder.prototype.appendBuffer = function(source) {
@@ -50,7 +51,7 @@ function makeAppender(encoder, size) {
5051
}
5152

5253
return this;
53-
}
54+
};
5455
}
5556

5657
BufferBuilder.prototype.appendUInt8 = makeAppender(Buffer.prototype.writeUInt8, 1);

0 commit comments

Comments
 (0)