1. #1
    Sencha User
    Join Date
    Oct 2007
    Location
    Berlin, Germany
    Posts
    889
    Vote Rating
    9
    wm003 will become famous soon enough

      1  

    Default Ext.util.base64 (encode/decode)

    Ext.util.base64 (encode/decode)


    There were so many base64 versions around but i haven't found an Ext-classed version of this so here it is

    call it with

    PHP Code:
    var myencodedstring Ext.util.base64.encode("Testtext"); //returns VGVzdHRleHQ=
    var mydecodedstring Ext.util.base64.decode("VGVzdHRleHQ="); //returns Testtext 
    PHP Code:
    Ext.util.base64 = {

        
    base64s "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
        
        
    encode: function(decStr){
            if (
    typeof btoa === 'function') {
                 return 
    btoa(decStr);            
            }
            var 
    base64s this.base64s;
            var 
    bits;
            var 
    dual;
            var 
    0;
            var 
    encOut "";
            while(
    decStr.length >= 3){
                
    bits = (decStr.charCodeAt(i++) & 0xff) <<16 | (decStr.charCodeAt(i++) & 0xff) <<decStr.charCodeAt(i++) & 0xff;
                
    encOut += base64s.charAt((bits 0x00fc0000) >>18) + base64s.charAt((bits 0x0003f000) >>12) + base64s.charAt((bits 0x00000fc0) >> 6) + base64s.charAt((bits 0x0000003f));
            }
            if(
    decStr.length -&& decStr.length -3){
                
    dual Boolean(decStr.length --1);
                
    bits = ((decStr.charCodeAt(i++) & 0xff) <<16) |    (dual ? (decStr.charCodeAt(i) & 0xff) <<0);
                
    encOut += base64s.charAt((bits 0x00fc0000) >>18) + base64s.charAt((bits 0x0003f000) >>12) + (dual base64s.charAt((bits 0x00000fc0) >>6) : '=') + '=';
            }
            return(
    encOut);
        },
        
        
    decode: function(encStr){
            if (
    typeof atob === 'function') {
                return 
    atob(encStr); 
            }
            var 
    base64s this.base64s;        
            var 
    bits;
            var 
    decOut "";
            var 
    0;
            for(; 
    i<encStr.length+= 4){
                
    bits = (base64s.indexOf(encStr.charAt(i)) & 0xff) <<18 | (base64s.indexOf(encStr.charAt(+1)) & 0xff) <<12 | (base64s.indexOf(encStr.charAt(+2)) & 0xff) << base64s.indexOf(encStr.charAt(+3)) & 0xff;
                
    decOut += String.fromCharCode((bits 0xff0000) >>16, (bits 0xff00) >>8bits 0xff);
            }
            if(
    encStr.charCodeAt(-2) == 61){
                return(
    decOut.substring(0decOut.length -2));
            }
            else if(
    encStr.charCodeAt(-1) == 61){
                return(
    decOut.substring(0decOut.length -1));
            }
            else {
                return(
    decOut);
            }
        }

    }; 

  2. #2
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,498
    Vote Rating
    46
    Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    FF has a built in function to do this as someone pointed out to me when I included base 64 encode functions in my Grid to Excel UX. See that thread for how to incorporate the native function if available.

  3. #3
    Sencha User
    Join Date
    Oct 2007
    Location
    Berlin, Germany
    Posts
    889
    Vote Rating
    9
    wm003 will become famous soon enough

      0  

    Default


    Quote Originally Posted by Animal View Post
    FF has a built in function to do this as someone pointed out to me when I included base 64 encode functions in my Grid to Excel UX. See that thread for how to incorporate the native function if available.
    ah, didn't know that...(that's why you posted it here...)..I'll check your Excel-thread again (which is quite impressive btw. it's a pity, IE6/7 do not support it)

  4. #4
    Sencha User
    Join Date
    Oct 2007
    Location
    Berlin, Germany
    Posts
    889
    Vote Rating
    9
    wm003 will become famous soon enough

      0  

    Default


    Quote Originally Posted by Animal View Post
    FF has a built in function to do this as someone pointed out to me when I included base 64 encode functions in my Grid to Excel UX. See that thread for how to incorporate the native function if available.
    Thanks, Animal. I updated the code to support that.
    However, if somebody will code an own global "atob" or "btoa" function, the Ext.util.base64 will generally fail. Everybody who uses it should keep this in mind.

  5. #5
    Ext User gounis's Avatar
    Join Date
    Aug 2007
    Posts
    39
    Vote Rating
    0
    gounis is on a distinguished road

      0  

    Default License for Ext.util.base64

    License for Ext.util.base64


    Hello,

    I would like to ask which is the license for using the Ext.util.base64.

    Thank you in advance.

  6. #6
    Sencha User
    Join Date
    Oct 2007
    Location
    Berlin, Germany
    Posts
    889
    Vote Rating
    9
    wm003 will become famous soon enough

      0  

    Default


    Quote Originally Posted by gounis View Post
    Hello,

    I would like to ask which is the license for using the Ext.util.base64.

    Thank you in advance.
    Free as in free beer and free speech

  7. #7
    Ext User
    Join Date
    Aug 2009
    Posts
    1
    Vote Rating
    0
    aditit is on a distinguished road

      0  

    Default how to add extension in symfony extjs project

    how to add extension in symfony extjs project


    I want to use base64.encode function .But it is not present in ext-all.js When I added code for base64.encode and called it in .js . But it says , Ext.util.base64.encode is not defined. What is the solution for it.
    Thanks in advance!

  8. #8
    Sencha User
    Join Date
    Oct 2007
    Location
    Berlin, Germany
    Posts
    889
    Vote Rating
    9
    wm003 will become famous soon enough

      0  

    Default


    Quote Originally Posted by aditit View Post
    I want to use base64.encode function .But it is not present in ext-all.js When I added code for base64.encode and called it in .js . But it says , Ext.util.base64.encode is not defined. What is the solution for it.
    Thanks in advance!
    did you really copy the whole code from post #1? Or just the code within the encode-function? To use "Ext.util.base64.encode" you need to copy the whole code.

  9. #9
    Sencha Premium Member
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    330
    Vote Rating
    1
    PranKe01 is on a distinguished road

      0  

    Default


    Hi guys,

    this function isn't in version 3.0 of ExtJS. I included the code myself but I get an error when using this function with a Word-File It says "INVALID_CHARACTER_ERR: DOM Exception 5" in this line:
    Code:
    return btoa(decStr);
    Commenting the following lines
    Code:
    if (typeof btoa === 'function') {
                 return btoa(decStr);
            }
    throws an error "TypeError: Value undefined does not allow function calls." at this line:
    Code:
    bits = (decStr.charCodeAt(i++) & 0xff) <<16 | (decStr.charCodeAt(i++) & 0xff) <<8 | decStr.charCodeAt(i++) & 0xff;
    I'm using this function with Adobe Air and I want to code ANY file with base64. First I create a air.ByteArray using stream.readBytes and then give that ByteArray to this function.

    Does anyone know another way in JS to code any file to base64?

    Thanks a lot!

  10. #10
    Sencha Premium Member
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    330
    Vote Rating
    1
    PranKe01 is on a distinguished road

      0  

    Default


    After hours of searching I finally found THE solution! None of the implementations workes with binary files or Word-files etc. But that code works like a charm Should be implemented in ExtJS!

    Code:
    var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    
    var encode64 = function(input) {
        input = escape(input);
        var output = "";
        var chr1, chr2, chr3 = "";
        var enc1, enc2, enc3, enc4 = "";
        var i = 0;
        
        do {
            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);
            
            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;
            
            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }
            
            output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4);
            chr1 = chr2 = chr3 = "";
            enc1 = enc2 = enc3 = enc4 = "";
        } while (i < input.length);
        
        return output;
    }
    
    var decode64 = function(input) {
        var output = "";
        var chr1, chr2, chr3 = "";
        var enc1, enc2, enc3, enc4 = "";
        var i = 0;
        
        var base64test = /[^A-Za-z0-9\+\/\=]/g;
        if (base64test.exec(input)) {
            Ext.Msg.alert("Warning", "The document contains invalid characters. Errors can occur when decoding it.");
        }
        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
        
        do {
            enc1 = keyStr.indexOf(input.charAt(i++));
            enc2 = keyStr.indexOf(input.charAt(i++));
            enc3 = keyStr.indexOf(input.charAt(i++));
            enc4 = keyStr.indexOf(input.charAt(i++));
            
            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;
            
            output = output + String.fromCharCode(chr1);
            
            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }
            
            chr1 = chr2 = chr3 = "";
            enc1 = enc2 = enc3 = enc4 = "";
        } while (i < input.length);
        
        return unescape(output);
    };

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..."