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

encoding-down

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

encoding-down

LevelDOWN wrapper supporting levelup@1 encodings

  • 2.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
243K
decreased by-70.98%
Maintainers
1
Weekly downloads
 
Created

What is encoding-down?

The encoding-down npm package is a codec layer for levelup that provides encoding and decoding of keys and values. It allows you to use different encodings for keys and values, making it easier to work with various data types in a LevelDB store.

What are encoding-down's main functionalities?

Basic Usage

This code demonstrates how to set up a LevelDB store with JSON encoding for values using encoding-down. It shows how to put and get a JSON object.

const levelup = require('levelup');
const leveldown = require('leveldown');
const encode = require('encoding-down');

const db = levelup(encode(leveldown('./mydb'), { valueEncoding: 'json' }));

db.put('key', { some: 'value' }, function (err) {
  if (err) return console.log('Ooops!', err);

  db.get('key', function (err, value) {
    if (err) return console.log('Ooops!', err);
    console.log('Got value:', value);
  });
});

Custom Encoding

This code demonstrates how to use a custom encoding for values in a LevelDB store. The custom encoding converts values to and from Buffers.

const levelup = require('levelup');
const leveldown = require('leveldown');
const encode = require('encoding-down');

const customEncoding = {
  encode: (val) => Buffer.from(val.toString()),
  decode: (val) => val.toString(),
  buffer: true,
  type: 'custom'
};

const db = levelup(encode(leveldown('./mydb'), { valueEncoding: customEncoding }));

db.put('key', 'custom value', function (err) {
  if (err) return console.log('Ooops!', err);

  db.get('key', function (err, value) {
    if (err) return console.log('Ooops!', err);
    console.log('Got value:', value);
  });
});

Binary Encoding

This code demonstrates how to use binary encoding for values in a LevelDB store. It shows how to put and get a binary value.

const levelup = require('levelup');
const leveldown = require('leveldown');
const encode = require('encoding-down');

const db = levelup(encode(leveldown('./mydb'), { valueEncoding: 'binary' }));

db.put('key', Buffer.from('binary value'), function (err) {
  if (err) return console.log('Ooops!', err);

  db.get('key', function (err, value) {
    if (err) return console.log('Ooops!', err);
    console.log('Got value:', value.toString());
  });
});

Other packages similar to encoding-down

FAQs

Package last updated on 26 Jan 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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