Is it feasible to implement a lz4 decompressor in JavaScript?

Sep 16, 2013 at 8:52 PM

I don't have much knowledge about compressors but we have a requirement in our application to compress the JavaScript code beforehand and decompress the code at runtime (self-extracting JavaScript). Lz4hc looks ideal for our requirements considering it's decompression speeds. but I couldn't find any decoders for Lz4/Lz4hc written in JavaScript. So I am planing to write one and have following queries.
  1. Is it possible to implement a Lz4 decoder in JavaScript?
  2. If possible what are the considerations I need to take into account ?
    • It is a phone application.
    • Script file size is 1.5 - 4 mb after minifying with yuicompressor.
    • Encoding ?? base64/utf-16/latin-1 (this is where I am not getting it).
  3. If not possible, are there any alternatives
    • I already tried other tools like Packer and CrunchMe which generates a self-extractable compressed JavaScript code. But the code extracted by both of them are causing some JavaScript syntax exception which is nearly impossible to debug considering the script size.
Your help is highly appreciated.

Sep 19, 2013 at 8:53 AM
I don't know if it works how fast (or rather slow) it is, but I found this:
Sep 19, 2013 at 4:13 PM
Thanks Krashan. I'll verify node-lz4.
Sep 19, 2013 at 4:27 PM
Please note, though, LZ4Stream which I've implemented is not compatible with node-lz4 stream. So you are limited to "synchronous" mode of node-lz4 (it does not stream it just encodes/decodes whole blocks).