'use strict';

/**
 * File或Blob对象转Base64字符串
 * @param {*} fileOrBlob File或Blob对象
 * @returns {Promise<string>}
 */
function fileOrBlobToBase64(fileOrBlob) {
  return new Promise(function (resolve, reject) {
    var reader = new FileReader();

    reader.onload = function (e) {
      return resolve(e.target.result);
    };

    reader.onerror = reject;
    reader.readAsDataURL(fileOrBlob);
  });
}

module.exports = fileOrBlobToBase64;
