Reputation: 1504
I have following code:
Buffer.from([1, 5, 'asd'])
Which produces:
<Buffer 01 05 00>
My question is how can I get my initial data back, in this case:
[1, 5, 'asd']
Upvotes: 1
Views: 817
Reputation: 5853
buf.toJson() is something you are looking for, however string asd
is not valid buffer value.
Buffer stores an array of bytes (int values from 0
to 255
). When asd
is a string that needs 3 bytes (1 for each letter). In other words string is also an array of bytes.
const buf = Buffer.from([1, 5, 'asd'])
const debuf = buf.toJson().data // output: [1,5,0]
Upvotes: 1