{"_id":"buffer-json","_rev":"195030","name":"buffer-json","description":"JSON.stringify & JSON.parse which can encode/decode buffers.","dist-tags":{"latest":"2.0.0"},"maintainers":[{"name":"jprichardson","email":""}],"time":{"modified":"2021-06-03T12:29:07.000Z","created":"2015-06-18T21:57:07.209Z","2.0.0":"2019-02-25T15:58:57.535Z","1.0.0":"2015-06-18T21:57:07.209Z"},"users":{},"author":{"name":"JP Richardson"},"repository":{"type":"git","url":"git+https://github.com/jprichardson/buffer-json.git"},"versions":{"2.0.0":{"name":"buffer-json","version":"2.0.0","description":"JSON.stringify & JSON.parse which can encode/decode buffers.","main":"index.js","scripts":{"test":"standard --fix && node test.js"},"repository":{"type":"git","url":"git+https://github.com/jprichardson/buffer-json.git"},"keywords":["JSON","parse","stringify","buffer","reviver","replacer","base64"],"author":{"name":"JP Richardson"},"license":"MIT","bugs":{"url":"https://github.com/jprichardson/buffer-json/issues"},"homepage":"https://github.com/jprichardson/buffer-json#readme","devDependencies":{"standard":"^12.0.1","tape":"^4.10.1"},"gitHead":"ab0f350b5e6c715b56329308ffc73761ff10b98f","_id":"buffer-json@2.0.0","_npmVersion":"6.1.0","_nodeVersion":"10.5.0","_npmUser":{"name":"jprichardson","email":"jprichardson@gmail.com"},"dist":{"shasum":"f73e13b1e42f196fe2fd67d001c7d7107edd7c23","size":1959,"noattachment":false,"key":"/buffer-json/-/buffer-json-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/buffer-json/download/buffer-json-2.0.0.tgz"},"maintainers":[{"name":"jprichardson","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/buffer-json_2.0.0_1551110337419_0.6827815894594524"},"_hasShrinkwrap":false,"publish_time":1551110337535,"_cnpm_publish_time":1551110337535},"1.0.0":{"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":""}],"dist":{"shasum":"39f5ca5e00cc44ed8463ae422265ff083ef17b3f","size":1526,"noattachment":false,"key":"/buffer-json/-/buffer-json-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/buffer-json/download/buffer-json-1.0.0.tgz"},"directories":{},"publish_time":1434664627209,"_cnpm_publish_time":1434664627209,"_hasShrinkwrap":false}},"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","_attachments":{},"homepage":"https://github.com/jprichardson/buffer-json#readme","bugs":{"url":"https://github.com/jprichardson/buffer-json/issues"},"license":"MIT"}