Process large Base64 documents without blocking the event loop.
Configurable chunk size option to optimise for your use case.
Note:
Base64 in Node.js is already crazy fast. Breaking the work up into chunks and adding async logic adds overhead. If you aren't dealing with large files it will probably be more efficient to just block the event loop for the small amount of time it takes Node.js to process Base64 synchronously.
$ npm run exampleRegistering 4 asynchronous jobs...Encoding 100 MB with default Node.js Buffer API...Base64 encode completeHi, I'm an asynchronous job, and I'm late by 231msHi, I'm an asynchronous job, and I'm late by 238msHi, I'm an asynchronous job, and I'm late by 239msHi, I'm an asynchronous job, and I'm late by 245msRegistering 4 asynchronous jobs...Encoding 100 MB with base64-async in chunks of 250 kB...Hi, I'm an asynchronous job, and I'm on timeHi, I'm an asynchronous job, and I'm on timeHi, I'm an asynchronous job, and I'm on timeHi, I'm an asynchronous job, and I'm on timeBase64 encode complete
Notice how none of the async jobs can start until the Buffer API has finished encoding and stops blocking the event loop? With base64-async the async jobs can execute in-between each chunk of data.
As you can see, the total processing time is longer with base64-async (as we spend some time paused waiting for the event loop). However, if you have an idea of the size of the data you'll be working with, you can play around with the chunk size to get better performance.
The included benchmarking tool accepts arguments to help you test this: