README.md 1.99 KB
Newer Older
Adam Procter's avatar
Adam Procter committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97

# level-codec

<img alt="LevelDB Logo" height="100" src="http://leveldb.org/img/logo.svg">

**[LevelUP's](https://github.com/rvagg/node-levelup) encoding logic.**

[![Build Status](https://travis-ci.org/Level/codec.png)](https://travis-ci.org/Level/codec)
[![Greenkeeper badge](https://badges.greenkeeper.io/Level/codec.svg)](https://greenkeeper.io/)

## API

### Codec([opts])

  Create a new codec, with a global options object.

  This could be something like

```js
var codec = new Codec(db.options);
```

### #encodeKey(key[, opts])

  Encode `key` with given `opts`.

### #encodeValue(value[, opts])

  Encode `value` with given `opts`.

### #encodeBatch(batch[, opts])

  Encode `batch` ops with given `opts`.

### #encodeLtgt(ltgt)

  Encode the ltgt values of option object `ltgt`.

### #decodeKey(key[, opts])

  Decode `key` with given `opts`.

### #decodeValue(value[, opts])

  Decode `value` with given `opts`.

### #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.

### #keyAsBuffer([opts])

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

### #valueAsBuffer([opts])

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

### #encodings

  The supported encodings as object of form

```js
{
  "name": {
    "encode": Function,
    "decode": Function,
    "buffer": Boolean,
    "type": String
  }
}
```

  Currently supported encodings:

  - utf8
  - json
  - binary
  - hex
  - ascii
  - base64
  - ucs2
  - ucs-2
  - utf16le
  - utf-16le
  - none (bypass level-codec)

## Publishers

* [@juliangruber](https://github.com/juliangruber)
* [@ralphtheninja](https://github.com/ralphtheninja)

## License &amp; copyright

Copyright (c) 2012-2015 LevelUP contributors.

LevelUP is licensed under the MIT license. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE.md file for more details.