简体   繁体   中英

How to append to Buffer in Node.js

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?

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)))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM