MCPcopy Create free account
hub / github.com/craftzdog/react-native-quick-base64 / decodeBase64

Function decodeBase64

cpp/QuickBase64Impl.cpp:30–44  ·  view source on GitHub ↗

Mirrors V8's Uint8Array.fromBase64 (TC39-aligned): - last_chunk_handling_options::loose accepts inputs without '=' padding - decode_up_to_bad_char mirrors V8's ArrayBufferFromBase64 - base64_default_or_url accepts both standard (+/) and URL-safe (-_) alphabets

Source from the content-addressed store, hash-verified

28// - decode_up_to_bad_char mirrors V8's ArrayBufferFromBase64
29// - base64_default_or_url accepts both standard (+/) and URL-safe (-_) alphabets
30std::string decodeBase64(const std::string& input) {
31 size_t max_len = simdutf::maximal_binary_length_from_base64(input.data(), input.size());
32 std::string result(max_len, '\0');
33 size_t out_len = max_len;
34 auto r = simdutf::base64_to_binary_safe(
35 input.data(), input.size(), result.data(), out_len,
36 simdutf::base64_default_or_url,
37 simdutf::last_chunk_handling_options::loose,
38 /*decode_up_to_bad_char*/ true);
39 if (r.error != simdutf::error_code::SUCCESS) {
40 throw std::runtime_error("Input is not valid base64-encoded data");
41 }
42 result.resize(out_len);
43 return result;
44}
45
46} // namespace
47

Callers 1

base64ToArrayBufferMethod · 0.85

Calls 3

dataMethod · 0.80
sizeMethod · 0.80

Tested by

no test coverage detected