Posted By

szsk on 08/02/06


Tagged

javascript datascheme


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

xaviaracil
shachi
vali29
ki4ngel
wirenaught


base64encode


 / Published in: JavaScript
 

URL: http://www.onicos.com/staff/iz/amuse/javascript/expert/base64.txt

  1. if( btoa == undefined ) {
  2. var b64ec = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  3. var btoa = function( str ) {
  4. var out = "", i = 0, len = str.length;
  5. while( i < len ) {
  6. var c1 = str.charCodeAt( i++ ) & 0xff;
  7. if( i == len ) {
  8. out += b64ec.charAt( c1 >> 2 )
  9. + b64ec.charAt( ( c1 & 0x3 ) << 4 )
  10. + "==";
  11. break;
  12. }
  13. var c2 = str.charCodeAt( i++ );
  14. if( i == len ) {
  15. out += b64ec.charAt( c1 >> 2 )
  16. + b64ec.charAt( ( ( c1 & 0x3 ) << 4 ) | ( ( c2 & 0xF0 ) >> 4 ) )
  17. + b64ec.charAt( ( c2 & 0xF ) << 2 )
  18. + "=";
  19. break;
  20. }
  21. var c3 = str.charCodeAt( i++ );
  22. out += b64ec.charAt( c1 >> 2 )
  23. + b64ec.charAt( ( ( c1 & 0x3 ) << 4 ) | ( ( c2 & 0xF0 ) >> 4 ) )
  24. + b64ec.charAt( ( ( c2 & 0xF ) << 2 ) | ( ( c3 & 0xC0 ) >> 6 ) )
  25. + b64ec.charAt( c3 & 0x3F );
  26. }
  27. return out;
  28. }
  29. }

Report this snippet  

You need to login to post a comment.