
Product
Socket Now Supports pylock.toml Files
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
uint8-base64
Advanced tools
You can find a lot of NPM libraries dealing with base64 encoding and decoding.
However, we could not find one that would have as input AND output an Uint8Array. This library does exactly this.
This library is pretty fast and will convert over 500 Mb per second in NodeJS as well as in the browser.
If you need at the end a text rather than an Uint8Array it is also extremely fast to convert the Uint8Array to text using a TextEncoder:
const base64 = encode(bytes);
const string = new TextDecoder('utf8').decode(base64);
$ npm i uint8-base64
import { encode } from 'uint8-base64';
const result = encode(Uint8Array.from([65])); // an array containing 'A'
// result is Uint8Array(4) [ 81, 81, 61, 61 ] ('QQ==')
import { encode } from 'uint8-base64';
const bytes = new Uint8Array(256 * 1024 * 1024).map((_, i) =>
Math.floor(Math.random() * 256),
);
console.time('base64');
const base64 = encode(bytes);
const string = new TextDecoder('utf8').decode(base64);
console.timeEnd('base64');
console.log(string.slice(0, 100));
This code takes 330ms on my MacBook pro M4 to encode 256Mb of data. The encoding itself takes 240ms while the conversion to text takes 50ms.
import { decode } from '..';
const result = decode(Uint8Array.from([81, 81, 61, 61])); // an array containing 'QQ=='
// result is Uint8Array(1) [ 65 ] ('A')
The code was largely inspired by: https://gist.github.com/enepomnyaschih/72c423f727d395eeaa09697058238727
FAQs
Encode and decode base64 to and from Uint8Array
We found that uint8-base64 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
Security News
Research
Socket uncovered two npm packages that register hidden HTTP endpoints to delete all files on command.
Research
Security News
Malicious Ruby gems typosquat Fastlane plugins to steal Telegram bot tokens, messages, and files, exploiting demand after Vietnam’s Telegram ban.