Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Edit</strong> There appears to be a better LZW solution that handles Unicode strings correctly at <a href="http://pieroxy.net/blog/pages/lz-string/index.html" rel="noreferrer">http://pieroxy.net/blog/pages/lz-string/index.html</a> (Thanks to pieroxy in the comments).</p> <hr> <p>I don't know of any gzip implementations, but the <a href="http://jsolait.net/" rel="noreferrer">jsolait library</a> (the site seems to have gone away) has functions for LZW compression/decompression. The code is covered under the <a href="http://www.gnu.org/licenses/lgpl.txt" rel="noreferrer">LGPL</a>.</p> <pre><code>// LZW-compress a string function lzw_encode(s) { var dict = {}; var data = (s + "").split(""); var out = []; var currChar; var phrase = data[0]; var code = 256; for (var i=1; i&lt;data.length; i++) { currChar=data[i]; if (dict[phrase + currChar] != null) { phrase += currChar; } else { out.push(phrase.length &gt; 1 ? dict[phrase] : phrase.charCodeAt(0)); dict[phrase + currChar] = code; code++; phrase=currChar; } } out.push(phrase.length &gt; 1 ? dict[phrase] : phrase.charCodeAt(0)); for (var i=0; i&lt;out.length; i++) { out[i] = String.fromCharCode(out[i]); } return out.join(""); } // Decompress an LZW-encoded string function lzw_decode(s) { var dict = {}; var data = (s + "").split(""); var currChar = data[0]; var oldPhrase = currChar; var out = [currChar]; var code = 256; var phrase; for (var i=1; i&lt;data.length; i++) { var currCode = data[i].charCodeAt(0); if (currCode &lt; 256) { phrase = data[i]; } else { phrase = dict[currCode] ? dict[currCode] : (oldPhrase + currChar); } out.push(phrase); currChar = phrase.charAt(0); dict[code] = oldPhrase + currChar; code++; oldPhrase = phrase; } return out.join(""); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload