base64-async helps us in processing large Base64 documents without blocking the event loop, one can configure chunk size option to optimise for your use case.
This module exposes: b64, encode and decode methods which accepts (input, [options]) and returns a promise on innvocation.
Get it:npm install --save base64-async
Sample usage:
123456789101112131415161718
constb64=require('base64-async');constfs=require('fs');constbuffer=fs.readFileSync('somehugefile.jpg');b64.encode(fileBuffer).then(b64String=>console.log(b64String));// aGkgbXVt... b64.decode(b64String).then(buffer=>console.log(buffer));// <Buffer 68 69 20 6d 75 6d ... > // or, for the cool kids constb64String=awaitb64.encode(fileBuffer);constoriginalFileBuffer=awaitb64.decode(b64String);// which is equivalent to this constb64String=awaitb64(fileBuffer);constoriginalFileBuffer=awaitb64(b64String);// If no method is specified, buffers are encoded, strings are decoded