MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / atob

Function atob

app/rcc/scripts/parser/js/base64_encoded.js:24–44  ·  view source on GitHub ↗

* Decodes a Base64-encoded string into a binary string. * * @param {string} input - The Base64-encoded string * @returns {string} The decoded binary string * @throws {Error} If the input contains invalid Base64 characters

(input)

Source from the content-addressed store, hash-verified

22 * @throws {Error} If the input contains invalid Base64 characters
23 */
24function atob(input) {
25 input = input.replace(/[\s=]+$/, '');
26 const base64Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
27 let output = '';
28 let buffer = 0, bits = 0;
29
30 for (let i = 0; i < input.length; i++) {
31 let value = base64Chars.indexOf(input[i]);
32 if (value === -1)
33 throw new Error('Invalid character in Base64 string');
34
35 buffer = (buffer << 6) | value;
36 bits += 6;
37 if (bits >= 8) {
38 bits -= 8;
39 output += String.fromCharCode((buffer >> bits) & 0xFF);
40 }
41 }
42
43 return output;
44}
45
46//------------------------------------------------------------------------------
47// Frame Parser Function

Callers 1

parseFunction · 0.85

Calls 1

indexOfMethod · 0.45

Tested by

no test coverage detected