Let's say I am constructing a string, or series of bytes, of variable length, in Node. The documentation for buf.write says:
https://nodejs.org/api/buffer.html#buffer_buf_write_string_offset_length_encoding
Writes string to buf at offset according to the character encoding in encoding. The length parameter is the number of bytes to write. If buf did not contain enough space to fit the entire string, only a partial amount of string will be written. However, partially encoded characters will not be written.
Let's say I want to write more data than the Buffer has room for. What is the recommended way to grow it? It doesn't seem like there is a .grow
method or similar. I can call Buffer.from(buf)
to create a new Buffer, but that seems inefficient.