pieroxy / lz-string

LZ-based compression algorithm for JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to realize that only specified characters are allowed to appear in the compression result?

wll8 opened this issue · comments

commented

You have provided the following functions, but none of them meet the requirements, because in my use case only specified characters are allowed to appear in the compression result.

  • compress
  • compressToUTF16
  • compressToBase64
  • compressToEncodedURIComponent
  • compressToUint8Array

Transmission of characters other than 12AB is not allowed in my use case.

Suppose I need to compress BBC, without lz-string, I might do this:

var userDict = `12AB`
var split = userDict.slice(0, 1)
var sysDict = userDict.slice(1)
var table = {
  A: sysDict.repeat(1), // 2AB
  B: sysDict.repeat(2), // 2AB2AB
  C: sysDict.repeat(3), // 2AB2AB2AB
}
var table2 = Object.entries(table).reduce((acc, [key, val]) => (acc[val]= key, acc), {})

// the string to be compressed
var str = `BBC`

// ['2AB2AB', '2AB2AB', '2AB2AB2AB'].join('1')
var compressed = str.split(``).map(str => table[str]).join(split)
// compressed = '2AB2AB12AB2AB12AB2AB2AB'

var decompressed = compressed.split(split).map(str => table2[str]).join(``)

However, I managed to control the encoding result within the range of 12AB, but failed to compress the data. How can I get help with lz-string?

commented

Sorry for duplicate of this:

#169 (comment)