$ gnpm install codecs
Create an binary encoder/decoder for Node's build in types like, json, utf-8, hex.
npm install codecs
Useful to support value encodings similar to leveldb's.
var codecs = require('codecs')
var json = codecs('json')
console.log(json.encode({hello: 'world'})) // new Buffer('{"hello":"world"}')
console.log(json.decode(new Buffer('{"hello":"world"}'))) // {hello: 'world'}
var codec = codecs(type, [fallback])Create a new codec.
Supported types are
If an unknown type is passed-in, the fallback is used if given, else binary.
If you want to use a custom codec you can pass in an object containing a an encode and decode method and that will be returned.
var buf = codec.encode(value)Encode a value to a buffer.
var value = codec.decode(buf)Decode a buffer to a value.
MIT
Copyright 2013 - present © cnpmjs.org | Home |