All Projects → Level → codec

Level / codec

Licence: MIT license
Encode keys, values and range options, with built-in or custom encodings.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to codec

Binary
Generic and fast binary serializer for Go
Stars: ✭ 86 (+218.52%)
Mutual labels:  encoding, codec
packager
A levelup package helper for distributing with an abstract-leveldown compatible back-end.
Stars: ✭ 20 (-25.93%)
Mutual labels:  level, levelup
subleveldown
Split a levelup database into sublevels with their own keyspace, encoding and events.
Stars: ✭ 117 (+333.33%)
Mutual labels:  level, levelup
ffcvt
ffmpeg convert wrapper tool
Stars: ✭ 32 (+18.52%)
Mutual labels:  encoding, codec
Minih264
Minimalistic H264/SVC encoder single header library
Stars: ✭ 390 (+1344.44%)
Mutual labels:  encoding, codec
sirdez
Glorious Binary Serialization and Deserialization for TypeScript.
Stars: ✭ 20 (-25.93%)
Mutual labels:  encoding, buffer
mem
A convenience package bundling levelup and memdown.
Stars: ✭ 23 (-14.81%)
Mutual labels:  level, levelup
Binary Parser
Blazing-fast declarative parser builder for binary data
Stars: ✭ 422 (+1462.96%)
Mutual labels:  encoding, buffer
Ffmpeg Video Player
An FFmpeg and SDL Tutorial.
Stars: ✭ 149 (+451.85%)
Mutual labels:  encoding, codec
haskell-church-encodings
🌀 Church encodings written in Haskell
Stars: ✭ 23 (-14.81%)
Mutual labels:  encoding
go-disk-buffer
This package helps to work with huge amount of data, which cannot be stored in RAM
Stars: ✭ 39 (+44.44%)
Mutual labels:  buffer
hdradio
HD Radio SDR Receiver
Stars: ✭ 15 (-44.44%)
Mutual labels:  codec
WinDev-Utility
A utility for windows developers
Stars: ✭ 17 (-37.04%)
Mutual labels:  utility
gendesk
🌿 Generate .desktop files and download .png icons by specifying a minimum of information
Stars: ✭ 101 (+274.07%)
Mutual labels:  utility
gilfoyle
Distributed video encoding, hosting and streaming (WIP)
Stars: ✭ 73 (+170.37%)
Mutual labels:  encoding
hashids.pm
Hashids, ported for Perl
Stars: ✭ 15 (-44.44%)
Mutual labels:  encoding
koa-xml-body
koa middleware to parse xml request body
Stars: ✭ 36 (+33.33%)
Mutual labels:  encoding
biguint-format
Node.js module to format big uint numbers from a byte array or a Buffer
Stars: ✭ 16 (-40.74%)
Mutual labels:  buffer
srclient
Golang Client for Schema Registry
Stars: ✭ 188 (+596.3%)
Mutual labels:  codec
react-pendulum
A React Context utility library.
Stars: ✭ 15 (-44.44%)
Mutual labels:  utility

level-codec

Encode keys, values and range options, with built-in or custom encodings.

📌 This module will soon be deprecated, because it is superseded by level-transcoder.

level badge npm Node version npm Test Coverage Status JavaScript Style Guide Backers on Open Collective Sponsors on Open Collective

Usage

If you are upgrading: please see UPGRADING.md.

const Codec = require('level-codec')
const codec = Codec({ keyEncoding: 'json' })
const key = codec.encodeKey({ foo: 'bar' })
console.log(key) // -> '{"foo":"bar"}'
console.log(codec.decodeKey(key)) // -> { foo: 'bar' }

API

codec = Codec([opts])

Create a new codec, with a global options object.

codec.encodeKey(key[, opts])

Encode key with given opts.

codec.encodeValue(value[, opts])

Encode value with given opts.

codec.encodeBatch(batch[, opts])

Encode batch ops with given opts.

codec.encodeLtgt(ltgt)

Encode the ltgt values of option object ltgt.

codec.decodeKey(key[, opts])

Decode key with given opts.

codec.decodeValue(value[, opts])

Decode value with given opts.

codec.createStreamDecoder([opts])

Create a function with signature (key, value), that for each key-value pair returned from a levelup read stream returns the decoded value to be emitted.

codec.keyAsBuffer([opts])

Check whether opts and the global opts call for a binary key encoding.

codec.valueAsBuffer([opts])

Check whether opts and the global opts call for a binary value encoding.

codec.encodings

The builtin encodings as object of form

{
  [type]: encoding
}

See below for a list and the format of encoding.

Builtin Encodings

Type Input Stored as Output
utf8 String or Buffer String or Buffer String
json Any JSON type JSON string Input
binary Buffer, string or byte array Buffer As stored
hex
ascii
base64
ucs2
utf16le
utf-16le
String or Buffer Buffer String
none a.k.a. id Any type (bypass encoding) Input* As stored

* Stores may have their own type coercion. Whether type information is preserved depends on the abstract-leveldown implementation as well as the underlying storage (LevelDB, IndexedDB, etc).

Encoding Format

An encoding is an object of the form:

{
  encode: function (data) {
    return data
  },
  decode: function (data) {
    return data
  },
  buffer: Boolean,
  type: 'example'
}

All of these properties are required.

The buffer boolean tells consumers whether to fetch data as a Buffer, before calling your decode() function on that data. If buffer is true, it is assumed that decode() takes a Buffer. If false, it is assumed that decode takes any other type (usually a string).

To explain this in the grand scheme of things, consider a store like leveldown which has the ability to return either a Buffer or string, both sourced from the same byte array. Wrap this store with encoding-down and it'll select the most optimal data type based on the buffer property of the active encoding. If your decode() function needs a string (and the data can legitimately become a UTF8 string), you should set buffer to false. This avoids the cost of having to convert a Buffer to a string.

The type string should be a unique name.

Contributing

Level/codec is an OPEN Open Source Project. This means that:

Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.

See the Contribution Guide for more details.

Donate

To sustain Level and its activities, become a backer or sponsor on Open Collective. Your logo or avatar will be displayed on our 28+ GitHub repositories and npm packages. 💖

Backers

Open Collective backers

Sponsors

Open Collective sponsors

License

MIT © 2012-present Contributors.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].