I am using a library which on call of a function returns the toString of a buffer.
The exact code is
return Buffer.concat(stdOut).toString('utf-8');
But I don't want string version of it.
I just want the buffer
So how to convert string back to buffer.
Something like if
var bufStr = Buffer.concat(stdOut).toString('utf-8'); //convert bufStr back to only Buffer.concat(stdOut).
How to do this?
I tried doing
var buf = Buffer.from(bufStr, 'utf-8');
But it throws utf-8 is not a function. When I do
var buf = Buffer.from(bufStr);
It throws TypeError : this is not a typed array.
Thanks
You can do:
var buf = Buffer.from(bufStr, 'utf8');
But this is a bit silly, so another suggestion would be to copy the minimal amount of code out of the called function to allow yourself access to the original buffer. This might be quite easy or fairly difficult depending on the details of that library.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With