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)
};
};
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn