📅  最后修改于: 2022-03-11 15:02:23.913000             🧑  作者: Mango
let buf = Buffer.from('Hello, World', 'utf8');
let obj = { buffer: buf };
obj = JSON.parse(JSON.stringify(obj));
// { type: 'Buffer',
// data: [ 72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100 ] }
obj.buffer;
// To convert from JSON representation back to a buffer, use `Buffer.from()`
obj.buffer = Buffer.from(obj.buffer);
obj.buffer.toString('utf8'); // 'Hello, World'