'use strict';

/**
 * Base64或dataURI转unit8数组
 * @param {*} base64 Base64或dataURI数据
 * @returns {Uint8Array}
 */
function base64ToUnit8Array(base64) {
  base64 = base64.replace(/^data.*?,/, '');
  var byteString = window.atob(base64);
  var arrayBuffer = new ArrayBuffer(byteString.length);
  var unit8array = new Uint8Array(arrayBuffer);

  for (var i = 0; i < byteString.length; i++) {
    unit8array[i] = byteString.charCodeAt(i);
  }

  return unit8array;
}

module.exports = base64ToUnit8Array;
