buf.toJSON()
- 返回:{Object}
- 返回该 Buffer 实例的 JSON 表达式。当字符串化一个 Buffer 实例时会隐式调用 JSON.stringify() 这个函数。
例子:
const buf = Buffer.from('test');const json = JSON.stringify(buf);console.log(json);// Prints: '{"type":"Buffer","data":[116,101,115,116]}'const copy = JSON.parse(json, (key, value) => { ???return value && value.type === 'Buffer' ? Buffer.from(value.data) : value;});console.log(copy.toString());// Prints: 'test'
buf.toJSON()
原文地址:https://www.cnblogs.com/lalalagq/p/9908515.html