G
G
Galdar Turin2020-07-09 23:30:59
Node.js
Galdar Turin, 2020-07-09 23:30:59

How to limit the buffer by bytes and write only to the first byte?

In bl.append(Buffer.alloc(2, [34], 'hex'))I want to write 1 byte 22, and leave the rest empty. It should turn out like this 22 00 , but I can’t figure out how to do it.

bl.append(Buffer.from([ obj.header ])) // Тег
bl.append(Buffer.alloc(2, [34], 'hex'))


Found a way just like this, but it doesn't work
a = Buffer.alloc(2)
a[1] = [34]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
grinat, 2020-07-10
@Galdar

Buffer.concat([Buffer.from('22'), Buffer.alloc(hop empty nada)])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question