src/encoding/base64.js
function s2r(t, u = false) {
  // TODO check btoa alternative
  const b64 = u ? b64u : b64s;
  let a;
  let c;

  let l = 0;
  let s = 0;

  return stream.transform(t, value => {
    const r = [];
    const tl = value.length;
    for (let n = 0; n < tl; n++) {
      if (l && (l % 60) === 0 && !u) {
        r.push("\r\n");
      }
      c = value[n];
      if (s === 0) {
        r.push(b64.charAt((c >> 2) & 63));
        a = (c & 3) << 4;
      } else if (s === 1) {
        r.push(b64.charAt(a | ((c >> 4) & 15)));
        a = (c & 15) << 2;
      } else if (s === 2) {
        r.push(b64.charAt(a | ((c >> 6) & 3)));
        l += 1;
        if ((l % 60) === 0 && !u) {
          r.push("\r\n");
        }
        r.push(b64.charAt(c & 63));
      }
      l += 1;
      s += 1;
      if (s === 3) {
        s = 0;
      }
    }
    return r.join('');
  }, () => {
    const r = [];
    if (s > 0) {
      r.push(b64.charAt(a));
      l += 1;
      if ((l % 60) === 0 && !u) {
        r.push("\r\n");
      }
      if (!u) {
        r.push('=');
        l += 1;
      }
    }
    if (s === 1 && !u) {
      if ((l % 60) === 0 && !u) {
        r.push("\r\n");
      }
      r.push('=');
    }
    return r.join('');
  });
}
function s2r(t, u = false) {
  // TODO check btoa alternative
  const b64 = u ? b64u : b64s;
  let a;
  let c;

  let l = 0;
  let s = 0;

  return stream.transform(t, value => {
    const r = [];
    const tl = value.length;
    for (let n = 0; n < tl; n++) {
      if (l && (l % 60) === 0 && !u) {
        r.push("\r\n");
      }
      c = value[n];
      if (s === 0) {
        r.push(b64.charAt((c >> 2) & 63));
        a = (c & 3) << 4;
      } else if (s === 1) {
        r.push(b64.charAt(a | ((c >> 4) & 15)));
        a = (c & 15) << 2;
      } else if (s === 2) {
        r.push(b64.charAt(a | ((c >> 6) & 3)));
        l += 1;
        if ((l % 60) === 0 && !u) {
          r.push("\r\n");
        }
        r.push(b64.charAt(c & 63));
      }
      l += 1;
      s += 1;
      if (s === 3) {
        s = 0;
      }
    }
    return r.join('');
  }, () => {
    const r = [];
    if (s > 0) {
      r.push(b64.charAt(a));
      l += 1;
      if ((l % 60) === 0 && !u) {
        r.push("\r\n");
      }
      if (!u) {
        r.push('=');
        l += 1;
      }
    }
    if (s === 1 && !u) {
      if ((l % 60) === 0 && !u) {
        r.push("\r\n");
      }
      r.push('=');
    }
    return r.join('');
  });
}
function s2r ( t , u = false ) { // TODO check btoa alternative const b64 = u ? b64u : b64s ; let a ; let c ; let l = 0 ; let s = 0 ; return stream . transform ( t , value => { const r = [ ] ; const tl = value . length ; for ( let n = 0 ; n < tl ; n ++ ) { if ( l && ( l % 60 ) === 0 && ! u ) { r . push ( "\r\n" ) ; } c = value [ n ] ; if ( s === 0 ) { r . push ( b64 . charAt ( ( c >> 2 ) & 63 ) ) ; a = ( c & 3 ) << 4 ; } else if ( s === 1 ) { r . push ( b64 . charAt ( a | ( ( c >> 4 ) & 15 ) ) ) ; a = ( c & 15 ) << 2 ; } else if ( s === 2 ) { r . push ( b64 . charAt ( a | ( ( c >> 6 ) & 3 ) ) ) ; l += 1 ; if ( ( l % 60 ) === 0 && ! u ) { r . push ( "\r\n" ) ; } r . push ( b64 . charAt ( c & 63 ) ) ; } l += 1 ; s += 1 ; if ( s === 3 ) { s = 0 ; } } return r . join ( '' ) ; } , ( ) => { const r = [ ] ; if ( s > 0 ) { r . push ( b64 . charAt ( a ) ) ; l += 1 ; if ( ( l % 60 ) === 0 && ! u ) { r . push ( "\r\n" ) ; } if ( ! u ) { r . push ( '=' ) ; l += 1 ; } } if ( s === 1 && ! u ) { if ( ( l % 60 ) === 0 && ! u ) { r . push ( "\r\n" ) ; } r . push ( '=' ) ; } return r . join ( '' ) ; } ) ; }
Convert binary array to radix-64
@param {Uint8Array | ReadableStream<Uint8Array>} t Uint8Array to convert
@param {bool} u if true, output is URL-safe
@returns {String | ReadableStream<String>} radix-64 version of input string
@static
Convert binary array to radix - 64