MCPcopy
hub / github.com/BlueWallet/BlueWallet / uint8ArrayToBase64

Function uint8ArrayToBase64

blue_modules/uint8array-extras/index.js:154–172  ·  view source on GitHub ↗
(array, { urlSafe = false } = {})

Source from the content-addressed store, hash-verified

152const MAX_BLOCK_SIZE = 65_535;
153
154export function uint8ArrayToBase64(array, { urlSafe = false } = {}) {
155 assertUint8Array(array);
156
157 let base64;
158
159 if (array.length < MAX_BLOCK_SIZE) {
160 // Required as `btoa` and `atob` don't properly support Unicode: https://developer.mozilla.org/en-US/docs/Glossary/Base64#the_unicode_problem
161 base64 = globalThis.btoa(String.fromCodePoint.apply(this, array));
162 } else {
163 base64 = '';
164 for (const value of array) {
165 base64 += String.fromCodePoint(value);
166 }
167
168 base64 = globalThis.btoa(base64);
169 }
170
171 return urlSafe ? base64ToBase64Url(base64) : base64;
172}
173
174export function base64ToUint8Array(base64String) {
175 assertString(base64String);

Callers 5

_onReadUniformResourceFunction · 0.90
onBarCodeReadFunction · 0.90
bbqr.test.tsFile · 0.90
toStringMethod · 0.90
stringToBase64Function · 0.85

Calls 2

assertUint8ArrayFunction · 0.85
base64ToBase64UrlFunction · 0.85

Tested by

no test coverage detected