Welcome to the chromium-base64
module - where encoding meets lightning speed! ⚡
chromium-base64
is a supercharged JavaScript module for Base64 encoding and decoding. It's like base64-js
but on steroids! 💪 With performance gains of nearly +80% (almost double the speed 🏎️), it's the new heavyweight champion in the encoding arena!
Our hero, Matias Affolter 🦸♂️, delved deep into the Base64 algorithm and discovered the secret sauce used in Chromium's implementation by Nick Galbreath. This module is a testament to their combined genius, featuring low-level JavaScript (LLJS) close to asm.js style. It's like C and JS had a baby that's super efficient! 🍼
npm install chrominium-base64
Importing and using chromium-base64
is a walk in the park:
var { B64chromium } = require('chromium-base64');
// `/dist/browser.min.js` --> var base64 = new window.B64chromium();
var base64 = new B64chromium();
var prefixpng = "data:image/png;base64,";
var base64str = "iVBORw0KGgoAAAANSUhEUgAAAGMAAABrCAMAAABUtszKAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAABIUExURWySsQkAAA0AJyUVHA4AAN2Ha/m9l0dwTP///xEPPPKlg2gvLy4hMq5VT/jWrB8pWok9PeTazKOCbzxRf9G3cw0UYu/vj2NdX+nzxzMAAAAIdFJOU/r///////8AlmOzPQAAB9VJREFUaN7tmOmCozoOhQELpg0mgCHw/m86krzbbOmZ+++qqrsCAX8+2myo/vyD9h/zp/rzz9u/jH8ZVwbOpDP8/H9lADQ87oS2OqODV5zqjQI7emTEqNDwo4T/lWGdM5W2eo58UFO9IaSWkxCzwvqXjFNCSWLMeqPlhnFOENu2FiDCTFD9yrCZlNm+oXXdJgpFiLmKfvWDm5q61ptG23bUU3puvXBY9cpNDZuuaxSx7yhGNttZfNYJ3jKgHL9p6mPXNWzdZhC75rOFz+AVI/ipiQw17PhTg1Ti223bvoevE0wZleoq2E1mAHonN+EoFcV933R8XYQpINU5oikM6nbfFxyh6oZqwqhsS+rPyGtwzygQdMRnFM5eTwvasUwmKnnQLiDVCcL6P72tqTe9rcioqmWRR0f5W+aeO3hgWELKmHBuOHVVLdWEjPVYMObouJMML4VUGcIlUR3PiogAVByLxj67or/0LoC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qGBC7KMveuhbXCP21Jl8y4JzRiPhVr93MG8jx9VZfMP4LQFw1rniVR08AAAAASUVORK5CYII="; // Made with pixa.pics
console.log(prefixpng + base64.bytesToBase64(base64.base64ToBytes(base64str)));
//console.log(base64.base64ToBytes(base64str)) // -> Uint8Array
Based on a base64 string of 128kB:
base64-js
(most popular "2023" base64 npm module) takes 2116ms for a thousand rounds of toBytes and toBase64.chromium-base64
zips through the same in just 1256ms! 🌪️
- Nick Galbreath - The original mastermind behind the high-performance base64 encoder/decoder in Chromium.
- Matias Affolter - The visionary who brought Nick's algorithm to the JavaScript world, enhancing it with the finesse of LLJS.
Licensed under the MIT License. See the LICENSE file for more details.
chromium-base64
isn't just a module; it's a revolution in Base64 encoding/decoding. Whether you're a coding newbie or a seasoned pro, this module is sure to add some zing to your project! 🌟
(PREFERABLY) RUN TEST WITH BINDING METHODS ONCE BEFORE LOADING TESTS:
DATA TESTED: iVBORw0KGgoAAAANSUhEUgAAAGcAAACaBAMAAABGY0sNAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAtUExURQQEB1AjCgACAgcHCeOiLH9/f+zs6fr22xAQE0FBRcHBvdqJHiEhJvbYevv2x2hvaBcAAA1uSURBVFjDfJjPa9vYFscFWvQHXeQKQRahQyUMXpiC4FLqDFmMzIUuzDwKQU1kso14k9XYJc8dMw0B0VYZvBgIbqzg3UN+r6KbBEMXwqUQwouLF6+lkIVxFm+TxZD8De+ceyX/VHohxo790Tn3nO8550pS9hvRpxdhCrxqij67NPylpp4/kF4WZr8jJgFA09MhXf/5V+nb3HeEECUFGUGZ/0qFtC9JQUmj4n/+JKV8q2kkU/gOtJAGEcKYmWZKS6BU3xljSUwnoxi/fZAOFZk5gsaURpSbIV0rdkj8A11lyix/I8RzBZtQix2W8ErsYDpEilHsX6YTDTpJ1iYhLcVSBP7hu1zUHRzBVfiPM7HP3NJcdDW1+EU9UmALmWJ38BU2NvU1h2ZMweWIekRUBWSTYd3Bsa6zKfmmQCA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2fX8gDd2BPTsHSSI0mM+WMQHTiOZRLlhjunohu5kBaDYHs6OXcsz1jqGAI6fgiKeblKv/x0rBHZGImz1E0zD5oNTcUsjN68d96hdBIQ0dfM1Nkmh5BCp4PeLqDZytJaQpRwiOpMJ01Ah/75W6c7W/g9A6nynMSV4pDb8p5PTpwf0apv4JW4TkyZ6HBljHDtsffijeVtRKv6XSmpKKAqH68ErLtS5RSb2tu+97hl3t/ypSgkX0poCyU8LiCDynBUQAeATJO1FRGkiCxDLm8vxV1HV1otrf8SbckQELWZJNPy7iFO4aNwRGRUaejlMJSWuAN0uM2hWZZgj8FfUPnt/uFatQGJmr2CwuAfoEG/v4OcbLD3RxAyDYlJ2lRFXBlia5W/n/EmdIqsfLwPcfwvvlOpE1nUGKSpov5gknzfn2QgZshpc2Uf3bmK/39A/1OKoLsklHgKjaB4hY45YErxObCEhgLy86ApX06mHNJj22PnBMsB8rKCOFTgvzdFWBnOsgYO1cqRNG1Og0JTnTKd2I1irXoYziCckeUdZ6AAG1uAuKKA2MRCrUTQ2Eucaxxj8lTh59XGS0TzylBCPf9hqCAE8QQALtIKHjFmjJdncqkR9z5kwGoYqOUhh/o9Bo1zTN5ckYKY9/EhY6jK3r0/8YhpjdNBn1TwXrZIQJoMzbyDBNQHVBuloUdRM1qMBaRqiWdqQEgXZi2rU14O2GLphUGTCXKLlRbEJEAYfiREXbfceOXyZ4/UBsgT6exMwvCqvhyGxeWwKCW1n7Z1t+2yYf0qOr6xYWR2V1+ob5XrjQapz7ZHXepqFJ/Y3hPLPzYyZ9tYDiCrvtBIQjqFOMTyotLxDIPMNwQFVaLsG4Ui5CujeYyA9DYgJqlOpihc50Mqg7A5ZojqLTmqk/lPAnq9R+hUzSuhMhB1sTNK25rrrv4HP7hvLGrPjUsAAAAASUVORK5CYII=
chromium-base64-->
Encoding Time (100x): 4.299999952316284 ms
Decoding Time (100x): 1.7000000476837158 ms
Combined Time (100x): 6.299999952316284 ms
base64-js-->
Encoding Time (100x): 11.099999964237213 ms
Decoding Time (100x): 1.5999999642372131 ms
Combined Time (100x): 8.100000023841858 ms
var b64chromium = new B64chromium();
var decode = b64chromium.base64ToBytes.bind(b64chromium);
var encode = b64chromium.bytesToBase64.bind(b64chromium);
var iter = 100;
chromium-base64
isn't just about speed; it's about innovation and pushing boundaries. We draw inspiration from the finest in the field - Google Chrome. 🌟
Google Chrome, renowned for its efficiency, uses a decoder that's a work of art in its own right. Developed by Nick Galbreath, this "high-performance base64 encoder/decoder" is a cornerstone of Chromium's codebase. 🛠️
What sets Chromium's implementation apart, and what we've embraced in chromium-base64
, is its unique approach to decoding. Traditional base64 decoders rely heavily on shifts, but Chromium's decoder plays it smart. It bypasses shifts entirely, opting instead for a method where bytes are looked up as "pre-shifted" 32-bit values. 🧠💡
This approach isn't just about being different; it's about being better. It results in a decoder that's not only fast but also more efficient and reliable.
For the curious minds who want to dive deeper into this marvel, check out the detailed implementation at Lemire's fastbase64. 📚
In chromium-base64
, we don't just code for today; we code for tomorrow. We're always on the lookout for ways to innovate and improve, keeping pace with the ever-evolving tech landscape. 🚀
Join us in this journey of exploration and excellence. With chromium-base64
, the future of encoding is here and now! 🌌
Note: "Chromium" and "Google Chrome" are trademarks of Google LLC. The use of these names is for reference purposes only and does not imply any affiliation or endorsement by Google LLC.