From: https://github.com/ptarjan/base64url/blob/master/node.js
164325
function base64url_decode(input) {
    return Base64.decode(input.replace(/-/g, '+').replace(/_/g, '/'));
}
903108
def base64_url_decode(str)
      encoded_str = str.tr('-_', '+/')
      encoded_str += '=' while !(encoded_str.size % 4).zero?
      Base64.decode64(encoded_str)
    end
1203713
private static String base64Encode(byte[] data) {
        char c64[] = new char[data.length * 4 / 3 + 5];
        for (int i = 0, k = 0; i < data.length; i += 3, k += 4) {
            c64[k + 0] = (char) (data[i] >> 2);
            c64[k + 1] = (char) ((data[i] & 0x03) << 4);
            c64[k + 2] = c64[k + 3] = 64;
            if ((i + i) < data.length) {
                c64[k + 1] |= data[i + 1] >> 4;
                c64[k + 2] = (char) ((data[i + 1] & 0x0f) << 2);
            }
            if ((i + 2) < data.length) {
                c64[k + 2] |= data[i + 2] >> 6;
                c64[k + 3] = (char) (data[i + 2] & 0x3f);
            }
            for (int j = 0; j < 4; ++j) {
                c64[k + j] = BASE64_LUT.charAt(c64[k + j]);
            }
        }
        return new String(c64);
    }
50955
function getBase64 (file) { 
    var reader = new FileReader();
    reader.readAsDataURL(file);
    reader.onerror = function (error) {
        console.log('Error: ', error);
    };
    return reader;
}
480667
function decodeBase64(sEncoded) {

    // Input must be dividable with 4.
    if (!sEncoded || (sEncoded.length % 4) > 0) { return sEncoded; }
    else if (typeof (atob) != 'undefined') { return atob(sEncoded); }

    var nBits, i, sDecoded = '';
    var base64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';

    sEncoded = sEncoded.replace(/\W|=/g, '');
    for (i = 0; i < sEncoded.length; i += 4) {
        nBits =
            (base64.indexOf(sEncoded.charAt(i)) & 0xff) << 18 |
            (base64.indexOf(sEncoded.charAt(i + 1)) & 0xff) << 12 |
            (base64.indexOf(sEncoded.charAt(i + 2)) & 0xff) << 6 |
             base64.indexOf(sEncoded.charAt(i + 3)) & 0xff;
        sDecoded += String.fromCharCode(
            (nBits & 0xff0000) >> 16, (nBits & 0xff00) >> 8, nBits & 0xff);
    }
    return sDecoded.substring(0, sDecoded.length -
        ((sEncoded.charCodeAt(i - 2) == 61) ? 2 :
        (sEncoded.charCodeAt(i - 1) == 61 ? 1 : 0)));

}
1190896
function dataURItoBlob(dataURI) {
  // convert base64/URLEncoded data component to raw binary data held in a string
  var byteString;
  if (dataURI.split(',')[0].indexOf('base64') >= 0)
    byteString = atob(dataURI.split(',')[1]);
  else
    byteString = unescape(dataURI.split(',')[1]);

  // separate out the mime component
  var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];

  // write the bytes of the string to a typed array
  var ia = new Uint8Array(byteString.length);
  for (var i = 0; i < byteString.length; i++) {
    ia[i] = byteString.charCodeAt(i);
  }

  return new Blob([ia], {
    type: mimeString
  });
}
1067321
function base64ToBlob(base64Image, contentType) {
  // http://stackoverflow.com/questions/16245767/creating-a-blob-from-a-base64-string-in-javascript

  // Remove leading 'data:image/jpeg;base64,' or 'data:image/png;base64,'
  base64Image = base64Image.split(',')[1];

  let byteCharacters = atob(base64Image);

  // http://stackoverflow.com/questions/6259515/javascript-elegant-way-to-split-string-into-segments-n-characters-long
  let byteArrays = byteCharacters.match(/[\s\S]{1,512}/g).map( slice => {

    let byteNumbers = slice.split('').map( x => x.charCodeAt(0) );

    return new Uint8Array(byteNumbers);
  });

  let blob = new Blob(byteArrays, { type: contentType || 'image/jpg' /* or 'image/png' */ });

  return blob;
}
394632
private static String bytesToBase64(final byte[] body) {
    final String encoded = Base64.getEncoder().encodeToString(body);
    return encoded;
  }
1077365
function encodeToBase64(originalString) {
    const bytes = te.encode(originalString);
    const byteString = Array.from(bytes, byte => String.fromCharCode(byte)).join("");
    const encoded = btoa(byteString);
    return encoded;
  }
232193
def b64decode_url(istr):
    
    istr = encode_safe(istr)
    try:
        return urlsafe_b64decode(istr + '=' * (4 - (len(istr) % 4)))
    except TypeError as e:
        raise Error('Unable to decode base64: %s' % (e))
397952
def __decode_webpush_b64(self, data):
        
        missing_padding = len(data) % 4
        if missing_padding != 0:
            data += '=' * (4 - missing_padding)
        return base64.urlsafe_b64decode(data)
765831
private static byte[] base64Decode(String data) {
        int len = data.length();

        byte[] b64 = new byte[len * 3 / 4];
        byte[] buf = new byte[4];
        boolean done = false;

        for (int i = 0, j, k = 0; i < len && !done;) {
            buf[0] = buf[1] = buf[2] = buf[3] = 0;
            for (j = 0; j < 4 && i < len; ++j) {
                char c = data.charAt(i);
                if (c >= 'A' && c <= 'Z') {
                    c -= 'A';
                } else if (c >= 'a' && c <= 'z') {
                    c = (char) (c - 'a' + 26);
                } else if (c >= '0' && c <= '9') {
                    c = (char) (c - '0' + 52);
                } else if (c == '+') {
                    c = 62;
                } else if (c == '/') {
                    c = 63;
                } else if (c == '=' || c == '-') {
                    done = true;
                    break;
                } else {
                    ++i;
                    --j;
                    continue;
                }
                buf[j] = (byte) c;
                ++i;
            }

            if (k < b64.length && j >= 1) {
                b64[k++] = (byte) ((buf[0] << 2) | ((buf[1] & 0x30) >> 4));
            }
            if (k < b64.length && j >= 3) {
                b64[k++] = (byte) (((buf[1] & 0x0f) << 4) | ((buf[2] & 0x3c) >> 2));
            }
            if (k < b64.length && j >= 4) {
                b64[k++] = (byte) (((buf[2] & 0x03) << 6) | (buf[3] & 0x3f));
            }
        }
        return b64;
    }
161318
function urlToBase64 (url) {
  return new Promise((resolve, reject) => {
    request.get(url, (err, response, body) => {
      err && reject(err)
      resolve(body.toString('base64'))
    })
  })
}
471023
function byteArrayToBase64 (uint8) {
  var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
    , extraBytes = uint8.length % 3   // if we have 1 byte left, pad 2 bytes
    , output = ""
    , temp, length, i;

  function tripletToBase64 (num) {
    return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F];
  };

  // go through the array every three bytes, we'll deal with trailing stuff later
  for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) {
    temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]);
    output += tripletToBase64(temp);
  }

  // pad the end with zeros, but make sure to not forget the extra bytes
  switch (extraBytes) {
    case 1:
      temp = uint8[uint8.length - 1];
      output += lookup[temp >> 2];
      output += lookup[(temp << 4) & 0x3F];
      output += '==';
      break;
    case 2:
      temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1]);
      output += lookup[temp >> 10];
      output += lookup[(temp >> 4) & 0x3F];
      output += lookup[(temp << 2) & 0x3F];
      output += '=';
      break;
  }

  return output;
}
257685
function decode(data) {
  return io.tmpFile().then(function(file) {
    var buf = new Buffer(data, 'base64');
    return promise.checkedNodeCall(fs.writeFile, file, buf).then(function() {
      return io.tmpDir();
    }).then(function(dir) {
      var zip = new AdmZip(file);
      zip.extractAllTo(dir);  // Sync only? Why?? :-(
      return dir;
    });
  });
}
776667
function urlB64ToUint8Array(base64String) {
    const padding = '='.repeat((4 - base64String.length % 4) % 4);
    const base64 = (base64String + padding)
        .replace(/\-/g, '+')
        .replace(/_/g, '/');

    const rawData = self.atob(base64);
    const outputArray = new Uint8Array(rawData.length);

    for (let i = 0; i < rawData.length; ++i) {
        outputArray[i] = rawData.charCodeAt(i);
    }
    return outputArray;
}
841117
function encode64s(input) {
        var swaps = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9","+","/"];
        var input_binary = "";
        var output = "";
        var temp_binary;
        var index;
        for (index=0; index < input.length; index++) {
          temp_binary = input.charCodeAt(index).toString(2);
          while (temp_binary.length < 8) {
            temp_binary = "0"+temp_binary;
          }
          input_binary = input_binary + temp_binary;
          while (input_binary.length >= 6) {
            output = output + swaps[parseInt(input_binary.substring(0,6),2)];
            input_binary = input_binary.substring(6);
          }
        }
        if (input_binary.length == 4) {
          temp_binary = input_binary + "00";
          output = output + swaps[parseInt(temp_binary,2)];
          output = output + "=";
        }
        if (input_binary.length == 2) {
          temp_binary = input_binary + "0000";
          output = output + swaps[parseInt(temp_binary,2)];
          output = output + "==";
        }
        return output;
      }