    for (let i = 0; i < len; i++) {
      binary += String.fromCharCode(bytes[i]);
    }
    return btoa(binary);
  };

  Base64.DecodeToTypedArray = function(input, output) {
    const nInLen = input.length;
    const nOutLen = Base64.getDecodedBufferLength(input);
    let nMod3 = 0;
    let nMod4 = 0;
    let nUint24 = 0;
    let nOutIdx = 0;

    if (nOutLen > output.byteLength) {
      throw new Error('Output buffer too small to decode.');
    }

    for (let nInIdx = 0; nInIdx < nInLen; nInIdx++) {
   