B2G/gaia/apps/email/js/ext/mailapi/worker-bootstrap.js
/**
 * Decode a Uint8Array/DataView into a unicode string given the encoding of the
 * byte stream.  Wrap TextDecoder to provide hex and base64 decoding (which it
 * does not provide).
 */
Decode a Uint8Array/DataView into a unicode string given the encoding of the
byte stream.  Wrap TextDecoder to provide hex and base64 decoding (which it
does not provide).
Decode a Uint8Array / DataView into a unicode string given the encoding of the byte stream . Wrap TextDecoder to provide hex and base64 decoding ( which it does not provide ) .
function decode(view, encoding) {
  var sbits, i;
  switch (encoding) {
    case 'base64':
    case 'binary':
      sbits = new Array(view.length);
      for (i = 0; i < view.length; i++) {
        sbits[i] = String.fromCharCode(view[i]);
      }
      if (encoding === 'base64')
        return window.btoa(sbits.join(''));
      return sbits.join('');
    case 'hex':
      sbits = new Array(view.length / 2);
      for (i = 0; i < view.length; i += 2) {
        var nib = view[i], c;
        if (nib <= 57)
          c = 16 * (nib - 48);
        else if (nib < 97)
          c = 16 * (nib - 64 + 10);
        else
          c = 16 * (nib - 97 + 10);
        nib = view[i+1];
        if (nib <= 57)
          c += (nib - 48);
        else if (nib < 97)
          c += (nib - 64 + 10);
        else
          c += (nib - 97 + 10);
        sbits.push(String.fromCharCode(c));
      }
      return sbits.join('');
    case 'utf8':
      encoding = 'utf-8';
    default:
      if (!encoding)
        encoding = 'utf-8';
      return TextDecoder(encoding, ENCODER_OPTIONS).decode(view);
  }
}
function decode ( view , encoding ) { var sbits , i ; switch ( encoding ) { case 'base64' : case 'binary' : sbits = new Array ( view . length ) ; for ( i = 0 ; i < view . length ; i ++ ) { sbits [ i ] = String . fromCharCode ( view [ i ] ) ; } if ( encoding === 'base64' ) return window . btoa ( sbits . join ( '' ) ) ; return sbits . join ( '' ) ; case 'hex' : sbits = new Array ( view . length / 2 ) ; for ( i = 0 ; i < view . length ; i += 2 ) { var nib = view [ i ] , c ; if ( nib <= 57 ) c = 16 * ( nib - 48 ) ; else if ( nib < 97 ) c = 16 * ( nib - 64 + 10 ) ; else c = 16 * ( nib - 97 + 10 ) ; nib = view [ i + 1 ] ; if ( nib <= 57 ) c += ( nib - 48 ) ; else if ( nib < 97 ) c += ( nib - 64 + 10 ) ; else c += ( nib - 97 + 10 ) ; sbits . push ( String . fromCharCode ( c ) ) ; } return sbits . join ( '' ) ; case 'utf8' : encoding = 'utf-8' ; default : if ( ! encoding ) encoding = 'utf-8' ; return TextDecoder ( encoding , ENCODER_OPTIONS ) . decode ( view ) ; } }
Decode a Uint8Array/DataView into a unicode string given the encoding of the
 byte stream.
Decode a Uint8Array / DataView into a unicode string given the encoding of the byte stream .
// base64 wants a string, so go through binary first... // (btoa is binary JS string -> base64 ASCII string) // need to normalize the name (for now at least)