{"name":"buffer-json","version":"1.0.0","description":"Restore a Buffer from JSON (use with JSON.parse) or serialize a Buffer to JSON.","main":"index.js","scripts":{"test":"standard && mocha"},"repository":{"type":"git","url":"git+https://github.com/jprichardson/buffer-json.git"},"keywords":["JSON","parse","buffer","reviver"],"author":{"name":"JP Richardson"},"license":"MIT","bugs":{"url":"https://github.com/jprichardson/buffer-json/issues"},"homepage":"https://github.com/jprichardson/buffer-json#readme","devDependencies":{"semver":"^4.3.4"},"gitHead":"633d155f8a979c56661fd4ef324de48714412759","_id":"buffer-json@1.0.0","_shasum":"39f5ca5e00cc44ed8463ae422265ff083ef17b3f","_from":".","_npmVersion":"2.10.1","_nodeVersion":"2.1.0","_npmUser":{"name":"jprichardson","email":"jprichardson@gmail.com"},"maintainers":[{"name":"jprichardson","email":"jprichardson@gmail.com"}],"dist":{"shasum":"39f5ca5e00cc44ed8463ae422265ff083ef17b3f","tarball":"http://registry-npm.ywwl.com/buffer-json/download/buffer-json-1.0.0.tgz","integrity":"sha512-cF/zfC4jetmaOeeJuVYErpaCNzi8mgpTwXnW8sksyk6soXfDy6lK+Ra9ExGnB5OP8mieVHIo5IU0po74FR69+Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFXG7R0Rq82gpLp8ZV8DOh90rLSueeXKjuXu1IUXk18uAiEA+5Ade65jGaBTT+MXzXcPLefKMoS2jXyHFPwau2ZMQDc="}],"size":1526,"noattachment":false,"key":"/buffer-json/-/buffer-json-1.0.0.tgz"},"directories":{},"readme":"# buffer-json\n\n```\nnpm install buffer-json\n```\n\n```js\nconst BJSON = require('buffer-json')\n\nconst str = BJSON.stringify({ buf: Buffer.from('hello') })\n// => '{\"buf\":{\"type\":\"Buffer\",\"data\":\"base64:aGVsbG8=\"}}'\n\nBJSON.parse(str)\n// => { buf: <Buffer 68 65 6c 6c 6f> }\n```\n\nThe [`Buffer`](https://nodejs.org/api/buffer.html#buffer_buffer) class in Node.js is used to represent binary data. JSON does not specify a way to encode binary data, so the Node.js implementation of `JSON.stringify` represents buffers as an object of shape `{ type: \"Buffer\", data: [<bytes as numbers>] }`. Unfortunately, `JSON.parse` does not turn this structure back into a `Buffer` object:\n\n```\n$ node\n> JSON.parse(JSON.stringify({ buf: Buffer.from('hello world') }))\n{ buf:\n   { type: 'Buffer',\n     data: [ 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100 ] } }\n```\n\n`JSON.stringify` and `JSON.parse` accept arguments called [`replacer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter) and [`reviver`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Using_the_reviver_parameter) respectively which allow customizing the parsing/encoding behavior. This module provides a replacer which encodes Buffer data as a base64-encoded string, and a reviver which turns JSON objects which contain buffer-like data (either as arrays of numbers or strings) into `Buffer` instances. All other types of values are parsed/encoded as normal.\n\n## API\n\n### `stringify(value[, space])`\n\nConvenience wrapper for [`JSON.stringify`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) with the `replacer` described below.\n\n### `parse(text)`\n\nConvenience wrapper for [`JSON.parse`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse) with the `reviver` described below.\n\n### `replacer(key, value)`\n\nA [`replacer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter) implementation which turns every value that is a `Buffer` instance into an object of shape `{ type: 'Buffer', data: 'base64:<base64-encoded buffer content>' }`. Empty buffers are encoded as `{ type: 'Buffer', data: '' }`.\n\n### `reviver(key, value)`\n\nA [`reviver`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Using_the_reviver_parameter) implementation which turns every object of shape `{ type: 'Buffer', data: <array of numbers or string> }` into a `Buffer` instance.\n\n## Related modules\n\n- [`buffer-json-encoding`](https://github.com/lachenmayer/buffer-json-encoding): an [`abstract-encoding`](https://github.com/mafintosh/abstract-encoding) compatible JSON encoder/decoder which uses this module.\n\n## License\n\nMIT","publish_time":1434664627209,"_cnpm_publish_time":1434664627209,"dist-tags":{"latest":"2.0.0"}}