Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

level-codec

Package Overview
Dependencies
Maintainers
2
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

level-codec - npm Package Compare versions

Comparing version 7.1.0 to 8.0.0

test/as-buffer.js

6

lib/encodings.js

@@ -7,7 +7,3 @@ exports.utf8 = exports['utf-8'] = {

},
decode: function(data){
return typeof data === 'string'
? data
: String(data)
},
decode: identity,
buffer: false,

@@ -14,0 +10,0 @@ type: 'utf8'

{
"name": "level-codec",
"repository": "Level/codec",
"version": "7.1.0",
"version": "8.0.0",
"description": "Levelup's encoding logic",

@@ -6,0 +6,0 @@ "license": "MIT",

@@ -1,11 +0,11 @@

# level-codec
<img alt="LevelDB Logo" height="100" src="http://leveldb.org/img/logo.svg">
> Encoding logic for [`level(up)`](https://github.com/Level/levelup).
**[LevelUP's](https://github.com/rvagg/node-levelup) encoding logic.**
[![level badge][level-badge]](https://github.com/level/awesome)
[![npm](https://img.shields.io/npm/v/level-codec.svg)](https://www.npmjs.com/package/level-codec)
[![Travis](https://travis-ci.org/Level/codec.svg?branch=master)](https://travis-ci.org/Level/codec)
[![david](https://david-dm.org/Level/codec.svg)](https://david-dm.org/level/codec)
[![npm](https://img.shields.io/npm/dm/level-codec.svg)](https://www.npmjs.com/package/level-codec)
[![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

@@ -61,29 +61,49 @@

The supported encodings as object of form
The builtin encodings as object of form
```js
{
"name": {
"encode": Function,
"decode": Function,
"buffer": Boolean,
"type": String
}
[type]: encoding
}
```
Currently supported encodings:
See below for a list and the format of `encoding`.
- utf8
- json
- binary
- hex
- ascii
- base64
- ucs2
- ucs-2
- utf16le
- utf-16le
- none (bypass level-codec)
## 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`<br>`ascii`<br>`base64`<br>`ucs2`<br>`utf16le`<br>`utf-16le` | String or Buffer | Buffer | String
| `none` a.k.a. `id` | Any type (bypass encoding) | Input\* | As stored
<sup>\*</sup> 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:
```js
{
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.
## Publishers

@@ -96,4 +116,9 @@

Copyright (c) 2012-2017 LevelUP contributors.
Copyright (c) 2012-2017 `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.
`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.
[level-badge]: http://leveldb.org/img/badge.svg
[`encoding-down`]: https://github.com/level/encoding-down
[`abstract-leveldown`]: https://github.com/level/abstract-leveldown
[`leveldown`]: https://github.com/level/leveldown
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc