Hybrid View

  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
    Sencha User
    Join Date
    Mar 2012
    Posts
    211
    Vote Rating
    0
    hieu79vn is an unknown quantity at this point

      0  

    Default


    Hi Animal
    Could you tell me Where to find the base 64 encode funtion in Extjs?

    Thank you

  8. #8
    Sencha User Misiu's Avatar
    Join Date
    Jun 2012
    Location
    Poland
    Posts
    206
    Vote Rating
    33
    Misiu has a spectacular aura about Misiu has a spectacular aura about

      0  

    Default


    Base64 is currently not included in ExtJS SDK.
    But there are many ready-to-use extensions, just search forum

  9. #9
    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!

  10. #10
    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.

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..."