all files / lib/deps/binary/ base64.js

100% Statements 15/15
83.33% Branches 5/6
100% Functions 3/3
100% Lines 14/14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29                1297×     1297×   1294×     3000×    
'use strict';
 
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.btoa = exports.atob = undefined;
 
var _buffer = require('./buffer');
 
var _buffer2 = _interopRequireDefault(_buffer);
 
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 
function thisAtob(str) {
  var base64 = new _buffer2.default(str, 'base64');
  // Node.js will just skip the characters it can't decode instead of
  // throwing an exception
  if (base64.toString('base64') !== str) {
    throw new Error("attachment is not a valid base64 string");
  }
  return base64.toString('binary');
}
 
function thisBtoa(str) {
  return new _buffer2.default(str, 'binary').toString('base64');
}
 
exports.atob = thisAtob;
exports.btoa = thisBtoa;