2021年3月24日星期三

NodeJS - How to retrieve original data from a Buffer after use JSON.parse(JSON.stringify())

I am working with crypto library to send a POST request to update some data and for some reason I get as if I used JSON.parse(JSON.stringify(myBufferData)) to a Buffer data. I want to recover the original data.

How you can replicate my situation:

var buf = Buffer.from('abc');  var parsedBuf = JSON.parse(JSON.stringify(buf)); -> I faced with this result at some point.    buf.toString() -> Give the expected result ('abc').  parsedBuf.toString() -> Doesn't retrieve original data ('[object Object]').  

How can I retrieve the original data from parsedBuf ?

https://stackoverflow.com/questions/66791436/nodejs-how-to-retrieve-original-data-from-a-buffer-after-use-json-parsejson-s March 25, 2021 at 08:38AM

没有评论:

发表评论