G
G
Galdar Turin2020-08-17 14:13:35
Node.js
Galdar Turin, 2020-08-17 14:13:35

How to add the rest of the bytes to the buffer?

I create a buffer for two bytes, only one is written, how can I fill the last byte with 00? This option is not suitable because bl.length can be any length and 0 and 1 and 2 Wrote like this, but how terrible it is)
Buffer.alloc(2).write( String( bl.length ) )

Buffer.concat([Buffer.from([]), Buffer.alloc(2)])

Buffer.concat([ Buffer.from([bl.length]), Buffer.alloc(2 - Buffer.from([bl.length]).length ) ])

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Somewhere Intech, 2020-08-17
@Galdar

There are two functions for this
https://nodejs.org/api/buffer.html#buffer_buf_writ...
https://nodejs.org/api/buffer.html#buffer_buf_writ...
Same for reading only if BE write - do not read LE;)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question