How to inflate a string in Google AppsScript (or php)

239 views Asked by At

Trying to inflate a deflated string aHash.

The following returns non-ascii characters:

(gAppsScript:)

var decodedA = Utilities.base64Decode(aHash,Utilities.Charset.US_ASCII);
var decodedU = Utilities.base64Decode(aHash,Utilities.Charset.US_UTF_8);

Logger.log(Utilities.newBlob(decodedA).getDataAsString());
Logger.log(Utilities.newBlob(decodedU).getDataAsString());

(php:)

$uncompressed = gzinflate($yourFile);
echo $uncompressed;

This page can do it http://www.alderg.com/convert.html but is there a known built in alternative in js/gAppscript/php?

[Update]

This is cross posted in a different SE section and thanks to David for his answer. Following up, base64Decode is different from deflate decode. Is there a way to deflate a string in G-Appscript, perhaps with the UrlFetchApp?

1

There are 1 answers

0
Alan Wells On

Apps Script HTML Service can use jQuery and jQuery can inflate and deflate text. But this may not help you, depending on how you are using Apps Script. Are you using Apps Script in a Spreadsheet, a Doc, or something else? I'm not sure how you or your users are interacting with your code.

I found this jsFiddle on inflating and deflating with jQuery:

Link to jsFiddle Inflate/Deflate

function decode(str) {
  return decodeURIComponent(escape(RawDeflate.inflate($.base64.decode(str))));
}

$('#encode').click(function() {
    var str = $('#myinput').val(),
        encoded = encode(str),
        decoded = decode(encoded);

    //alert($.base64.decode(encoded));  //uncomment to see raw deflated value;
    $('#myinput_length').text('' + str.length);
    $('#output').val(encoded);
    $('#myoutput_length').text('' + encoded.length);
    $('#reconstructed').val(decoded);
    $('#reconstructed_length').text('' + decoded.length);

});

Also, I'm guessing that you want the Apps Script to go out and get something that was deflated by some other source? Another website? Originally deflated in some other language?