Skip to content

String Compression

W. "Mac" McMeans edited this page Aug 12, 2022 · 15 revisions

The localDataStorage utility incorporates SMAZ (a simple string compression library written in C) created by Salvatore Sanfilippo (https://github.com/antirez/smaz) under a BSD license. The derivative work included in this project (a javascript port of C code), was written by personalcomputer (https://github.com/personalcomputer/smaz.js), under the same BSD license.

The compression logic is suitable for crunching very short strings, but does not work well for general purpose data. It can compress text by 40-50% on average, with English phrases providing superior results, and even strings of two or three bytes can be optimized for space.

The original SMAZ appears to calculate compression ratios based on string length. For example, the following graphemes will each maintain a length of 1 after compression, but each will also conflate from 1 byte to 2 bytes: z, x, < and >. In contrast, the version included here is modified to prioritize byte count regardless of length, which is much more appropriate for efficient storage.

📝 NOTE: Dates, floats and integers are always stored compressed. This not only saves storage but also offers a measure of data protection through obfuscation.

localStorage Keys

The usual suspects:

set / get      clear      key      remove

The esoteric ones:

Array Keys:
push / pull, pullall      poke      contains      where

Broadcasting:
broadcast

Bypass:
forceset / forceget

Data Transfer:
import / export

Duplicates:
countdupes, showdupes, listdupes

Internals:
cancrunch      crunch / uncrunch

shufflestring / unshufflestring

xorstring

Management:
keys

Memory Consumption:

Memory Quota:
showquota

Query:
haskey, hasval, hastype

Security:
safeset / safeget

setscramblekey / getscramblekey

Type Check:
isarray      isbigint      isboolean      iscrunch

isdate      isfloat      isinteger      isnull

isnumber      isobject      isstring

showtype

Utility:
chopget      copy      softset      rename

Properties:

channel      length      quota      version

Settings:

verbosity

Memory Keys

Standard:

_set / _get      _clear      _key      _remove

Unconventional:

Data Sync:
_backup / _restore

Management:
_keys

Security:
_safeset / _safeget

Type Check:
_isarray      _isbigint      _isboolean      _iscrunch

_isdate      _isfloat      _isinteger      _isnull

_isnumber      _isobject      _isstring

_showtype

Utility:
_chopget      _copy      _softset      _rename

Clone this wiki locally