Reputation: 99970
Say I have a Buffer:
let b = Buffer.from('');
how can I append to b
? Is the only way to create a new Buffer?
b = Buffer.concat([b, z]);
on the same subject, is there a way to create a dynamic sized buffer, or should I use Array instead?
Upvotes: 9
Views: 8425
Reputation: 36299
To create a dynamic buffer use an array then concat
the array similar to this:
let chunks = []
stream
.on('data', chunk => chunks.push(chunk))
.on('close', () => console.log(Buffer.concat(chunks)))
Upvotes: 14