diff options
author | David Braun <NodeJS-box@snkmail.com> | 2013-03-26 12:14:52 -0300 |
---|---|---|
committer | Nathan Rajlich <nathan@tootallnate.net> | 2013-03-30 13:52:22 -0700 |
commit | 840a29fc0fd256a63b3f2f5e7528de5107a608a3 (patch) | |
tree | 1af35955e184eba14c13cebd55fead262fa897f3 /doc | |
parent | 9b8dd395536df3dbb21423dba888998f2cd36d2a (diff) | |
download | android-node-v8-840a29fc0fd256a63b3f2f5e7528de5107a608a3.tar.gz android-node-v8-840a29fc0fd256a63b3f2f5e7528de5107a608a3.tar.bz2 android-node-v8-840a29fc0fd256a63b3f2f5e7528de5107a608a3.zip |
buffer: change output of Buffer.prototype.toJSON()
Expand the JSON representation of Buffer to include type information
so that it can be deserialized in JSON.parse() without context.
Fixes #5110.
Fixes #5143.
Diffstat (limited to 'doc')
-rw-r--r-- | doc/api/buffer.markdown | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/doc/api/buffer.markdown b/doc/api/buffer.markdown index 268294fce0..f0c1c1c16b 100644 --- a/doc/api/buffer.markdown +++ b/doc/api/buffer.markdown @@ -114,9 +114,8 @@ See `buffer.write()` example, above. ### buf.toJSON() -Returns a JSON-representation of the Buffer instance, which is identical to the -output for JSON Arrays. `JSON.stringify` implicitly calls this function when -stringifying a Buffer instance. +Returns a JSON-representation of the Buffer instance. `JSON.stringify` +implicitly calls this function when stringifying a Buffer instance. Example: @@ -124,9 +123,13 @@ Example: var json = JSON.stringify(buf); console.log(json); - // '[116,101,115,116]' + // '{"type":"Buffer","data":[116,101,115,116]}' - var copy = new Buffer(JSON.parse(json)); + var copy = JSON.parse(json, function(key, value) { + return value && value.type === 'Buffer' + ? new Buffer(value.data) + : value; + }); console.log(copy); // <Buffer 74 65 73 74> |