Created
July 31, 2015 05:45
-
-
Save JavaScript-Packer/6eb1dbb94f8c511a0a06 to your computer and use it in GitHub Desktop.
LZW encoder, old compression used in GIF images. Also the function is used on http://www.whak.ca/packer/LZW(HAK).htm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function lzw_encode(u) { | |
var r, a, n = {}, t = (u + "").split(""), e = [], i = t[0], o = 256; | |
for (a = 1; a < t.length; a++) r = t[a], null != n[i + r] ? i += r :(e.push(i.length > 1 ? n[i] :i.charCodeAt(0)), | |
n[i + r] = o, o++, i = r); | |
for (e.push(i.length > 1 ? n[i] :i.charCodeAt(0)), a = 0; a < e.length; a++) e[a] = String.fromCharCode(e[a]); | |
return e.join(""); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment