1

I'm using a wrapper atm that makes JXG's Gzip utils a bunch easier. The unzipping a base64 encoded string part works rather nicely however I want to be able to turn it back into a base64 encoded string again. I somehow can't seem to wrap my head around it however, the function which unzips does the following:

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;
}

Now I need to reverse that, I have my array with numbers and wish to turn it into a byte string (could do the base64 encoding and gzip compression with php).

Any idea how to reverse the function above?

1 Answer 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 );
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.