dongyin2390 2014-11-28 04:49
浏览 76

如何在Google Apps脚本(或php)中为字符串充气

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条回答 默认 最新

  • dongta1824 2014-12-02 15:32
    关注

    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?

    评论

报告相同问题?

悬赏问题

  • ¥15 谁有RH342练习环境
  • ¥15 STM32F407 DMA中断问题
  • ¥15 uniapp连接阿里云无法发布消息和订阅
  • ¥25 麦当劳点餐系统代码纠错
  • ¥15 轮班监督委员会问题。
  • ¥15 基于作物生长模型下,有限水资源的最大化粮食产量的资源优化模型建立
  • ¥20 关于变压器的具体案例分析
  • ¥15 生成的QRCode圖片加上下載按鈕
  • ¥15 板材切割优化算法,数学建模,python,lingo
  • ¥15 科来模拟ARP欺骗困惑求解