Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have a browser gunzip an Ajax fetched gziped text file? [duplicate]

Assuming a server which cannot zip responses to user requests. A web developer nevertheless creates a myfile.txt.gz and stores it at http://www.mysite.com/myfile.txt.gz.

It is possible to have the browser automatically gunzip this compressed text file as part of the Ajax request and store the result in a var? If yes, how?

I am open to other compression algorithms if necessary.

Update

I am trying to use the following JQuery Ajax call:

var fetch = function() {

    $.ajax({
        type: 'GET',
        url:  "./data.txt.gz",
        headers: { "Accept-Encoding" : "gzip" },
        dataType: "text",
        async: true,
        success: function(result) {
            $("#midEnglob").text(result);
        },
        error: function(jqXHR, textStatus, errorThrown) {
            alert("Issue: "
                + textStatus + " "
                + errorThrown + " !");
        }

    });

}

but I get the following in my browser:

enter image description here

Any ideas?

like image 504
Jérôme Verstrynge Avatar asked Feb 13 '13 16:02

Jérôme Verstrynge


1 Answers

letting the browser uncompress it with Content-Encoding: gzip is probably the best. In case it doesn't work for your scenario, there are many LZW implementations in javascript like: https://gist.github.com/revolunet/843889

you might have to try out different implementations, i didn't check any of them myself.

like image 70
Christian Avatar answered Nov 07 '22 14:11

Christian