Skip to content

Commit

Permalink
Infer method for b64 to call based on input type
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechilds committed May 23, 2017
1 parent f0b9838 commit 97a6430
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ const validateOpts = (opts, chunkMultiple) => {
};

const b64 = (input, opts) => {
if (opts && ['encode', 'decode'].indexOf(opts.method) > -1) {
return b64[opts.method](input, opts);
if (input instanceof Buffer || typeof input === 'string') {
const method = input instanceof Buffer ? 'encode' : 'decode';
return b64[method](input, opts);
}

return Promise.reject(new Error('opts.method must be \'encode\' or \'decode\'.'));
return Promise.reject(new Error('input must be a buffer or string'));
};

b64.encode = (input, opts) => new Promise(resolve => {
Expand Down

0 comments on commit 97a6430

Please sign in to comment.