dist/node-base64-image.js
function encode(url) {
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { string: false, local: false };
  var callback = arguments[2];
  // eslint-disable-line
  if (_lodash2.default.isUndefined(url) || _lodash2.default.isNull(url) || !_lodash2.default.isString(url)) {
    return callback(new Error('URL is undefined or not properly formatted'));
  }

  if (options.local) {
    (0, _fs.readFile)(url, function (err, body) {
      if (err) {
        return callback(err);
      }

      /**
       * @todo Handle this better.
       */
      var result = options.string ? body.toString('base64') : new Buffer(body, 'base64');
      return callback(null, result);
    });
  } else {
    (0, _request2.default)({ url: url, encoding: null }, function (err, response, body) {
      if (err) {
        return callback(err);
      }

      if (!body) {
        return callback(new Error('Error retrieving image - Empty Body!'));
      }

      if (body && response.statusCode === 200) {
        /**
         * @todo Handle this better.
         */
        var result = options.string ? body.toString('base64') : new Buffer(body, 'base64');
        return callback(null, result);
      }

      return callback(new Error('Error retrieving image - Status Code ' + response.statusCode));
    });
  }
}
function encode(url) {
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { string: false, local: false };
  var callback = arguments[2];
  // eslint-disable-line
  if (_lodash2.default.isUndefined(url) || _lodash2.default.isNull(url) || !_lodash2.default.isString(url)) {
    return callback(new Error('URL is undefined or not properly formatted'));
  }

  if (options.local) {
    (0, _fs.readFile)(url, function (err, body) {
      if (err) {
        return callback(err);
      }

      /**
       * @todo Handle this better.
       */
      var result = options.string ? body.toString('base64') : new Buffer(body, 'base64');
      return callback(null, result);
    });
  } else {
    (0, _request2.default)({ url: url, encoding: null }, function (err, response, body) {
      if (err) {
        return callback(err);
      }

      if (!body) {
        return callback(new Error('Error retrieving image - Empty Body!'));
      }

      if (body && response.statusCode === 200) {
        /**
         * @todo Handle this better.
         */
        var result = options.string ? body.toString('base64') : new Buffer(body, 'base64');
        return callback(null, result);
      }

      return callback(new Error('Error retrieving image - Status Code ' + response.statusCode));
    });
  }
}
function encode ( url ) { var options = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : { string : false , local : false } ; var callback = arguments [ 2 ] ; // eslint-disable-line if ( _lodash2 . default . isUndefined ( url ) || _lodash2 . default . isNull ( url ) || ! _lodash2 . default . isString ( url ) ) { return callback ( new Error ( 'URL is undefined or not properly formatted' ) ) ; } if ( options . local ) { ( 0 , _fs . readFile ) ( url , function ( err , body ) { if ( err ) { return callback ( err ) ; } /**
       * @todo Handle this better.
       */ var result = options . string ? body . toString ( 'base64' ) : new Buffer ( body , 'base64' ) ; return callback ( null , result ) ; } ) ; } else { ( 0 , _request2 . default ) ( { url : url , encoding : null } , function ( err , response , body ) { if ( err ) { return callback ( err ) ; } if ( ! body ) { return callback ( new Error ( 'Error retrieving image - Empty Body!' ) ) ; } if ( body && response . statusCode === 200 ) { /**
         * @todo Handle this better.
         */ var result = options . string ? body . toString ( 'base64' ) : new Buffer ( body , 'base64' ) ; return callback ( null , result ) ; } return callback ( new Error ( 'Error retrieving image - Status Code ' + response . statusCode ) ) ; } ) ; } }
Encodes a remote or local image to Base64 encoded string or Buffer

@name encode
@param {string} url - URL of remote image or local path to image
@param {Object} [options={}] - Options object for extra configuration
@param {boolean} options.string - Returns a Base64 encoded string. Defaults to Buffer object
@param {boolean} options.local - Encode a local image file instead of a remote image
@param {fnCallback} callback - Callback function
@todo Option to wrap string every 76 characters for strings larger than 76 characters
@return {fnCallback} - Returns the callback
 
Callback for encode/decode functions

@callback fnCallback
@param {Object} Error object
@param {(string|Object)} Response string or Buffer object
Encodes a remote or local image to Base64 encoded string or Buffer