JavaScript: Decompress / inflate /unzip /ungzip strings

86,290

Solution 1

Take a look at this Stack Overflow question, the answers there contains references to multiple compressing engines implemented in javascript. Most of these are based on LZ77.

Solution 2

I don't know how you'd like that, but I like these implementations:

The first is fastest than second, We can usually ensure a fast server, however we don't know the performance of the client machine. Therefore I recommend you choose js-deflate and adjust your java (server side) to inflate.

https://github.com/dankogai/js-deflate

http://code.google.com/p/gzipjs/

Solution 3

I created a working example using pako, modern and fast Zlib port. http://jsfiddle.net/9yH7M/2/

Solution 4

there's this graphing library that has as part of it, a zlib implementation in javascript. if you scroll down this page a bit, you'll see it as a separate download. http://jsxgraph.uni-bayreuth.de/wp/download/

Solution 5

I found a working inflate implementation here:

http://www.onicos.com/staff/iz/amuse/javascript/expert/inflate.txt

If you want a slightly cleaner version that namespaces the algorithm, this one should work:

https://github.com/augustl/js-inflate

Keep in mind that gzipped "inflate" data is prefixed with a two-byte header, and suffixed with a four-byte checksum, which you will need to strip before passing to the algorithm.

Share:
86,290
febot
Author by

febot

I am. (See my LinkedIn profile. Open to job offers for USA, Germany, Austria, Switzerland). 2012 update: I'm a company-man, a team-player, a paradigm-shifter and a core-competancy-synergizer. :) PS: I worked for Red Hat / JBoss, so my answers may be biased. Currently work for Swiss Re.

Updated on March 27, 2020

Comments

  • febot
    febot about 4 years

    I'm looking for JavaScript implementation of string inflating algorithms. I want to compress on the server side (Java), and decompress on the client side (JavaScript).

    I've found:

    unzip strings in javascript
    That one is marked as answered with an answer for different problem. Other answers are also for something else (unzipping files in ZIP format).

    JavaScript inflate implementation (possibly FF 3.6 only)
    This is closest to what I need. However I'd like to have some alternatives.

    Suggestions?
    Thanks, Ondra

    Update: I have quite a specific use case, please don't answer "Don't do that in JavaScript." I am writing an "offline" reporting tool (once generated, it's put to a static store) and deflating may save megabytes for a single report. I am constrained by other apps so I can't store it as a zip file.