js/quilt_wrap.js
/**
     * Decodes a base64 string into a uint8 array if possible
     * @param str Base64 string
     * @return The uint8 array encode by the base64 string if possible
     * @throws An exception if the string does not represent a valid base64 code 
     */
Decodes a base64 string into a uint8 array if possible
@param str Base64 string
@return The uint8 array encode by the base64 string if possible
@throws An exception if the string does not represent a valid base64 code
Decodes a base64 string into a uint8 array if possible @param str Base64 string @return The uint8 array encode by the base64 string if possible @throws An exception if the string does not represent a valid base64 code
decode(str){
        Base64.init()
        var end = str.length
        while(end>=0 && str.charAt(end-1)=='=') end--
        if(end<2) throw '·Invalid Base64 string at· ' + end
        var m = (end%4)
        if(m==1) throw '·Invalid Base64 string at· ' + (end-1)
        if(m>1) m--
        var n = 3*Math.floor(end/4) + m
        var blob = new Uint8Array(n)
        var control =[[2,4,1],[4,2,1],[6,0,2]]
        var left, right
        var k=0
        var c=0
        for(var i=0; i<n; i++){
            left = Base64.a2i[str.charAt(k)]
            right = Base64.a2i[str.charAt(k+1)]
            if(left===undefined || right===undefined) throw '·Invalid Base64 string at· ' + k
            blob[i] =  (left << control[c][0]) |( right >> control[c][1])
            k+=control[c][2]
            c = (c+1)%3
        } 
        return blob
    }
decode ( str ) { Base64 . init ( ) var end = str . length while ( end >= 0 && str . charAt ( end - 1 ) == '=' ) end -- if ( end < 2 ) throw '·Invalid Base64 string at· ' + e d var m = ( end % 4 ) if ( m == 1 ) throw '·Invalid Base64 string at· ' + ( n d-1 ) if ( m > 1 ) m -- var n = 3 * Math . floor ( end / 4 ) + m var blob = new Uint8Array ( n ) var control = [ [ 2 , 4 , 1 ] , [ 4 , 2 , 1 ] , [ 6 , 0 , 2 ] ] var left , right var k = 0 var c = 0 for ( var i = 0 ; i < n ; i ++ ) { left = Base64 . a2i [ str . charAt ( k ) ] right = Base64 . a2i [ str . charAt ( k + 1 ) ] if ( left === undefined || right === undefined ) throw '·Invalid Base64 string at· ' + k blob [ i ] = ( left << control [ c ] [ 0 ] ) | ( right >> control [ c ] [ 1 ] ) k += control [ c ] [ 2 ] c = ( c + 1 ) % 3 } return blob }
Decodes a base64 string into a uint8 array if possible
 @param str Base64 string
 @return The uint8 array encode by the base64 string if possible
 @throws An exception if the string does not represent a valid base64 code
Decodes a base64 string into a uint8 array if possible @param str Base64 string @return The uint8 array encode by the base64 string if possible @throws An exception if the string does not represent a valid base64 code