{"_id":"buffer-json","_rev":"5-de5cb00377913212c515ca000b23750a","name":"buffer-json","description":"JSON.stringify & JSON.parse which can encode/decode buffers.","dist-tags":{"latest":"2.0.0"},"versions":{"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":"jprichardson@gmail.com"}],"dist":{"shasum":"39f5ca5e00cc44ed8463ae422265ff083ef17b3f","tarball":"https://registry.npmjs.org/buffer-json/-/buffer-json-1.0.0.tgz","integrity":"sha512-cF/zfC4jetmaOeeJuVYErpaCNzi8mgpTwXnW8sksyk6soXfDy6lK+Ra9ExGnB5OP8mieVHIo5IU0po74FR69+Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFXG7R0Rq82gpLp8ZV8DOh90rLSueeXKjuXu1IUXk18uAiEA+5Ade65jGaBTT+MXzXcPLefKMoS2jXyHFPwau2ZMQDc="}]},"directories":{}},"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":{"integrity":"sha512-+jjPFVqyfF1esi9fvfUs3NqM0pH1ziZ36VP4hmA/y/Ssfo/5w5xHKfTw9BwQjoJ1w/oVtpLomqwUHKdefGyuHw==","shasum":"f73e13b1e42f196fe2fd67d001c7d7107edd7c23","tarball":"https://registry.npmjs.org/buffer-json/-/buffer-json-2.0.0.tgz","fileCount":4,"unpackedSize":4926,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcdBDBCRA9TVsSAnZWagAAuEYP/i6EJbCwcBcnfymeU6sG\nOp+WRkNjAbxTlc61ynWbmxQCOzsDE65plaOhzbdD02oysxsiF4a7BGjPR0XK\nlBRcLi4lncmrrUvXgvVJfEt3iFKnNwbd8ZdmTMBKgnHZQLJjAPgOcAF54a7P\n91WtPGwkp2Q4nTeRaE/AHqCgNYuv1Xsh0M2OT2krV9TVC0nPgWHow8m1Iqxo\nGNbHFPkKzT9ek+l8WkIFlhbIPwAcXLwUEmMFx+5j4ChtL5pzpf6mEoaPpZsn\ntBU78fmbh9YZDg3hmEzUTN1yU69YHP0Hp592vr3ozO0sbNAMaGsCS0AGnxpP\n/CMC0LmgxwB+Bsv7NjcBRRUbHoerVL9SwTH0IbMZ8ElAnmTn6wlsYlnEFL6l\nXl/5K6a6hujgpdS8BfvH7j+EVIpE0bV9wC0EWTg1fkEW7ydsDS9b9J0K4jjI\ngXyrTp7wZma7QGEfMZ7xc4f3LhfWlbf1AShXHKz4W6oAeesbbUV4Gp75WDM3\nc6is1BVveUmlscJc5dQSYU4ZpDSOQPklOzeILgQtD2xKyzaChAcrOohLVcEo\nK4V0GWWmcsWVsvJ01MglyEI1Pz6+ZlKjRJV5703sh/ifHFmQqWQaawB0x9KO\nZb0y36G3A0ZorwCCtf2LdeyBuegzmM4v+aNBK9NC0y9L+Rymp/GUNXOzpr3V\nA4AJ\r\n=l/wy\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBsn0n94akXhER7V+0u8sRIupL7aOVn2qBM9r/ESIii3AiEAr2rGgVvSNtxm1UaMnPTovYz8Rld3eLC5wkBbx3oQw0k="}]},"maintainers":[{"name":"jprichardson","email":"jprichardson@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/buffer-json_2.0.0_1551110337419_0.6827815894594524"},"_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","maintainers":[{"name":"jprichardson","email":"jprichardson@gmail.com"}],"time":{"modified":"2022-06-13T05:15:21.563Z","created":"2015-06-18T21:57:07.209Z","1.0.0":"2015-06-18T21:57:07.209Z","2.0.0":"2019-02-25T15:58:57.535Z"},"homepage":"https://github.com/jprichardson/buffer-json#readme","keywords":["JSON","parse","stringify","buffer","reviver","replacer","base64"],"repository":{"type":"git","url":"git+https://github.com/jprichardson/buffer-json.git"},"author":{"name":"JP Richardson"},"bugs":{"url":"https://github.com/jprichardson/buffer-json/issues"},"license":"MIT","readmeFilename":"README.md"}