Created
October 10, 2019 20:26
-
-
Save wpscholar/d03a94a6e9699025c4c469632a8590f1 to your computer and use it in GitHub Desktop.
Utility functions for base64 encoding/decoding for buffers in Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Take a file and convert to a base64 encoded string. | |
* | |
* @param buffer A Buffer instance. | |
* @returns {string} A base64 encoded string. | |
*/ | |
function base64Encode(buffer) { | |
return new Buffer.from(buffer).toString('base64'); | |
} | |
/** | |
* Take a base64 encoded string and convert to a buffer. | |
* | |
* @param base64 | |
* @returns {Buffer} | |
*/ | |
function base64Decode(base64) { | |
return new Buffer.from(base64, 'base64'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment