@@ -79,3 +79,72 @@ Encoding.convert2UTF8 = function (str) {
7979 }
8080 return arrs . join ( '' ) ;
8181} ;
82+ Encoding . base64Chars = new Array (
83+ 'A' , 'B' , 'C' , 'D' , 'E' , 'F' , 'G' , 'H' ,
84+ 'I' , 'J' , 'K' , 'L' , 'M' , 'N' , 'O' , 'P' ,
85+ 'Q' , 'R' , 'S' , 'T' , 'U' , 'V' , 'W' , 'X' ,
86+ 'Y' , 'Z' , 'a' , 'b' , 'c' , 'd' , 'e' , 'f' ,
87+ 'g' , 'h' , 'i' , 'j' , 'k' , 'l' , 'm' , 'n' ,
88+ 'o' , 'p' , 'q' , 'r' , 's' , 't' , 'u' , 'v' ,
89+ 'w' , 'x' , 'y' , 'z' , '0' , '1' , '2' , '3' ,
90+ '4' , '5' , '6' , '7' , '8' , '9' , '+' , '/'
91+ ) ;
92+ Encoding . encodeBase64 = function ( str ) {
93+ if ( str == null || str . length == 0 ) return str ;
94+ var b64 = Encoding . base64Chars ;
95+ var length = str . length ;
96+ var index = 0 ;
97+ var buf = [ ] ;
98+ var c0 , c1 , c2 ;
99+ var c = 0 ;
100+ while ( index < length && c ++ < 60000 ) {
101+ c0 = str . charCodeAt ( index ++ ) ;
102+ buf [ buf . length ] = b64 [ c0 >> 2 ] ;
103+ if ( index < length ) {
104+ c1 = str . charCodeAt ( index ++ ) ;
105+ buf [ buf . length ] = b64 [ ( ( c0 << 4 ) & 0x30 ) | ( c1 >> 4 ) ] ;
106+ if ( index < length ) {
107+ c2 = str . charCodeAt ( index ++ ) ;
108+ buf [ buf . length ] = b64 [ ( ( c1 << 2 ) & 0x3c ) | ( c1 >> 6 ) ] ;
109+ buf [ buf . length ] = b64 [ c2 & 0x3F ] ;
110+ } else {
111+ buf [ buf . length ] = b64 [ ( ( c1 << 2 ) & 0x3c ) ] ;
112+ buf [ buf . length ] = '=' ;
113+ }
114+ } else {
115+ buf [ buf . length ] = b64 [ ( c0 << 4 ) & 0x30 ] ;
116+ buf [ buf . length ] = '=' ;
117+ buf [ buf . length ] = '=' ;
118+ }
119+ }
120+ return buf . join ( '' ) ;
121+ } ;
122+ Encoding . decodeBase64 = function ( str ) {
123+ if ( str == null || str . length == 0 ) return str ;
124+ var b64 = Encoding . base64Chars ;
125+ var xb64 = Encoding . xBase64Chars ;
126+ if ( Encoding . xBase64Chars == null ) {
127+ xb64 = new Object ( ) ;
128+ for ( var i = 0 ; i < b64 . length ; i ++ ) {
129+ xb64 [ b64 [ i ] ] = i ;
130+ }
131+ Encoding . xBase64Chars = xb64 ;
132+ }
133+ var length = str . length ;
134+ var index = 0 ;
135+ var buf = [ ] ;
136+ var c0 , c1 , c2 , c3 ;
137+ var c = 0 ;
138+ while ( index < length && c ++ < 60000 ) {
139+ c0 = xb64 [ str . charAt ( index ++ ) ] ;
140+ c1 = xb64 [ str . charAt ( index ++ ) ] ;
141+ c2 = xb64 [ str . charAt ( index ++ ) ] ;
142+ c3 = xb64 [ str . charAt ( index ++ ) ] ;
143+ if ( c2 == null ) c2 = 0 ;
144+ if ( c3 == null ) c3 = 0 ;
145+ buf [ buf . length ] = String . fromCharCode ( ( ( c0 << 2 ) & 0xff ) | c1 >> 4 ) ;
146+ buf [ buf . length ] = String . fromCharCode ( ( ( c1 << 4 ) & 0xff ) | c2 >> 2 ) ;
147+ buf [ buf . length ] = String . fromCharCode ( ( ( c2 << 6 ) & 0xff ) | c3 ) ;
148+ }
149+ return buf . join ( '' ) ;
150+ } ;
0 commit comments