简体   繁体   English

如何在Google AppsScript(或php)中膨胀字符串

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

Trying to inflate a deflated string aHash . 试图给放气的字符串aHash充气。

The following returns non-ascii characters: 以下内容返回非ASCII字符:

(gAppsScript:) (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:) (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? 该页面可以做到http://www.alderg.com/convert.html,但是js / gAppscript / php中是否有一个已知的内置替代项?

[Update] [更新]

This is cross posted in a different SE section and thanks to David for his answer. 这是交叉发布在不同的SE部分中,感谢David的回答。 Following up, base64Decode is different from deflate decode. 随后,base64Decode与deflate解码不同。 Is there a way to deflate a string in G-Appscript, perhaps with the UrlFetchApp? 是否可以使用UrlFetchApp在G-Appscript中压缩字符串?

Apps Script HTML Service can use jQuery and jQuery can inflate and deflate text. Apps Script HTML Service可以使用jQuery,而jQuery可以对文本进行充气和收缩。 But this may not help you, depending on how you are using Apps Script. 但这可能对您没有帮助,具体取决于您如何使用Apps Script。 Are you using Apps Script in a Spreadsheet, a Doc, or something else? 您在电子表格,文档或其他工具中使用Apps脚本吗? I'm not sure how you or your users are interacting with your code. 我不确定您或您的用户如何与您的代码进行交互。

I found this jsFiddle on inflating and deflating with jQuery: 我在用jQuery充气和缩小时发现了这个jsFiddle:

Link to jsFiddle Inflate/Deflate 链接到jsFiddle充气/放气

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? 另外,我猜您想让Apps脚本发布并获得其他来源放气的东西吗? Another website? 另一个网站? Originally deflated in some other language? 本来是用其他语言缩小的?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM