dictionary-encoding
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)
})
})
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