Code Monkey home page Code Monkey logo

dictionary-encoding's Introduction

dictionary-encoding stability

npm version build status test coverage downloads js-standard-style

Simple binary dictionary compression scheme. It takes a dictionary whose ids are integers, and a string or array of strings to compress according to the dictionary provided. Decomposing strings into parts that may be represented by the dictionary is left to a higher order module which would use this one to manage efficient encoding.

Usage

const encode = require('dictionary-encoding').encode
const decode = require('dictionary-encoding').decode


const dictionary = {
  'hello': '1',
  'world': '2',
  'ya\'ll': '3',
  ',': '4'
}

const invertedDictionary = {
  '1': 'hello',
  '2': 'world',
  '3': 'ya\'ll',
  '4': ','
}

encode(dictionary, ['hello', 'world', ',', 'ya\'ll'], function (err, buffer) {
  decode(invertedDictionary, buffer, function (err, arr) {
    console.log(arr) // ['hello', 'world', ',', 'ya\'ll']
  })
})

API

dictionaryEncoding

  • encode(dictionary, data, [cb]) Encode takes a dictionary and swaps each item with the value stored under the dictionary key. This function either returns a length prefixed stream of VLQ encoded buffers, or takes a callback which is provided a concatenation of the buffers that would otherwise be streamed.

  • decode(dictionary, data, [cb]) Encode takes a dictionary and swaps each item with the value stored under the dictionary key. This function either returns an object stream of strings, or takes a callback which is provided an array of the strings that would otherwise be streamed.

Installation

$ npm install dictionary-encoding

License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.