0.0.2 • Published 6 years ago

dictionary-encoding v0.0.2

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

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