Browse Source

docs

master
Dominic Tarr 12 years ago
parent
commit
241af8f56f
  1. 14
      README.md
  2. 7
      index.js

14
README.md

@ -1,5 +1,19 @@
# json-buffer
JSON functions that can convert buffers!
JSON mangles buffers by converting to an array...
which isn't helpful. json-buffers converts to base64 instead,
and deconverts base64 to a buffer.
``` js
var JSONB = require('json-buffer')
var Buffer = require('buffer').Buffer
var str = JSONB.stringify(new Buffer('hello there!'))
console.log(JSONB.parse(str)) //GET a BUFFER back
```
## License

7
index.js

@ -1,7 +1,10 @@
var Buffer = require('buffer').Buffer
exports.stringify = function stringify (o, a) {
//TODO: handle reviver/dehydrate function like normal
//and handle indentation, like normal.
//if anyone needs this... please send pull request.
exports.stringify = function stringify (o) {
if(o && Buffer.isBuffer(o))
o = o.toString('base64')
@ -19,7 +22,6 @@ exports.stringify = function stringify (o, a) {
if(!first)
s += ', '
first = false
s += array ? stringify(o[k]) : stringify(k) + ': ' + stringify(o[k])
}
}
@ -32,7 +34,6 @@ exports.stringify = function stringify (o, a) {
}
exports.parse = function (s) {
return JSON.parse(s, function (key, value) {
if('string' === typeof value && /==$/.test(value))
return new Buffer(value, 'base64')

Loading…
Cancel
Save