How to use base64-js

Comprehensive base64-js code examples:

How to use base64-js.substring:

5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
    base64 += chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)];
    base64 += chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)];
    base64 += chars[bytes[i + 2] & 63];
}
if (len % 3 === 2) {
    base64 = base64.substring(0, base64.length - 1) + '=';
}
else if (len % 3 === 1) {
    base64 = base64.substring(0, base64.length - 2) + '==';
}

How to use base64-js.toByteArray:

7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787


  return byteArray
}


function base64ToBytes (str) {
  return base64.toByteArray(base64clean(str))
}


function blitBuffer (src, dst, offset, length) {
  for (var i = 0; i < length; i++) {

How to use base64-js.fromByteArray:

6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883


function base64Slice (buf, start, end) {
  if (start === 0 && end === buf.length) {
    return base64.fromByteArray(buf)
  } else {
    return base64.fromByteArray(buf.slice(start, end))
  }
}


function utf8Slice (buf, start, end) {