This is example of converting String to a Buffer and back to String:
let bufferOne = Buffer.from(\'This is a buffer example.\');
console.log(bufferOne);
//
No native way for that, but I wrote a sample method for you:
function bufferFromBufferString(bufferStr) {
return Buffer.from(
bufferStr
.replace(/[<>]/g, '') // remove < > symbols from str
.split(' ') // create an array splitting it by space
.slice(1) // remove Buffer word from an array
.reduce((acc, val) =>
acc.concat(parseInt(val, 16)), []) // convert all strings of numbers to hex numbers
)
}
result:
const newBuffer = bufferFromBufferString('')
> newBuffer
> newBuffer.toString()
'This is a buffer example.'