codecs
Create an binary encoder/decoder for json, utf-8 or custom types
Last updated 7 years ago by mafintosh .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install codecs 
SYNC missed versions from official npm registry.

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.

Usage

const codecs = require('codecs')
const json = codecs('json')

console.log(json.encode({ hello: 'world' })) // Buffer.from('{"hello":"world"}')
console.log(json.decode(new Buffer('{"hello":"world"}'))) // { hello: 'world' }

API

const codec = codecs(type, [fallback])

Create a new codec.

Supported types are

  • utf8
  • json
  • ndjson
  • binary
  • hex
  • ascii
  • base64
  • ucs2
  • ucs-2
  • utf16le
  • utf-16le
  • binary

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. If you pass a compact encoder, then it will be converted into a codec for you and returned.

const buf = codec.encode(value)

Encode a value to a buffer.

const value = codec.decode(buf)

Decode a buffer to a value.

License

MIT

Current Tags

  • 3.1.0                                ...           latest (4 years ago)

9 Versions

  • 3.1.0                                ...           4 years ago
  • 3.0.0                                ...           5 years ago
  • 2.2.0                                ...           6 years ago
  • 2.1.0                                ...           7 years ago
  • 2.0.0                                ...           8 years ago
  • 1.2.1                                ...           9 years ago
  • 1.2.0                                ...           10 years ago
  • 1.1.0                                ...           10 years ago
  • 1.0.0                                ...           10 years ago
Maintainers (1)
Downloads
Total 22
Today 0
This Week 0
This Month 12
Last Day 0
Last Week 1
Last Month 1
Dependencies (0)
None
Dev Dependencies (2)

© 2010 - cnpmjs.org x YWFE | Home | YWFE