首页 文章

javascript数组返回字节字符串

提问于
浏览
1

我正在使用包装器atm,这使得JXG的Gzip工具更容易 . 解压缩base64编码的字符串部分工作相当不错但是我希望能够再次将其转换回base64编码的字符串 . 我似乎无法绕过它,但解压缩的功能如下:

unzipBase64AsArray: function(input, bytes) {
    bytes = bytes || 1;

    var dec = this.unzipBase64(input),
        ar = [], i, j, len;
    for (i = 0, len = dec.length/bytes; i < len; i++){
        ar[i] = 0;
        for (j = bytes-1; j >= 0; --j){
            ar[i] += dec.charCodeAt((i *bytes) +j) << (j *8);
        }
    }
    return ar;
}

现在我需要反转,我有我的数组数字,并希望把它变成一个字节字符串(可以使用php进行base64编码和gzip压缩) .

知道如何扭转上面的功能吗?

1 回答

  • 1
    zipArrayAsBase64: function( ar, bytes ) {
        bstr = '';
        for( i = 0; i < ar.length; ++i ) {
            for( j = 0; j < bytes; ++j ) {
                bstr += String.fromCharCode( ( ar[i] >> (j*8) ) & 0xFF );
            }
        }
        return this.zipBase64( bstr );
    }
    

相关问题