Method description:
Convert buffer object into json format.
Grammar:
buffer.toJSON()
Receive parameters:
None
Example:
var buf = new Buffer('test');
var json = JSON.stringify(buf);
console.log(json);
// '{"type":"Buffer","data":[116,101,115,116]}'
var copy = JSON.parse(json, function(key, value) {
Return value && value.type === 'Buffer'
? new Buffer(value.data)
: value;
});
console.log(copy);
//
Source code:
Buffer.prototype.toJSON = function() {
Return {
Type: 'Buffer',
Data: Array.prototype.slice.call(this, 0)
};
};