| 75 | } |
| 76 | |
| 77 | jsi::Object QuickBase64Impl::base64ToArrayBuffer( |
| 78 | jsi::Runtime& rt, |
| 79 | jsi::String b64, |
| 80 | bool removeLinebreaks |
| 81 | ) { |
| 82 | try { |
| 83 | std::string input; |
| 84 | auto cb = [&input](bool ascii, const void* data, size_t num) { |
| 85 | input.reserve(input.size() + num); |
| 86 | if (ascii) { |
| 87 | input.append(static_cast<const char*>(data), num); |
| 88 | } else { |
| 89 | const auto* u16 = static_cast<const char16_t*>(data); |
| 90 | for (size_t i = 0; i < num; ++i) { |
| 91 | input.push_back(static_cast<char>(u16[i])); |
| 92 | } |
| 93 | } |
| 94 | }; |
| 95 | b64.getStringData(rt, cb); |
| 96 | if (removeLinebreaks) { |
| 97 | input.erase(std::remove(input.begin(), input.end(), '\n'), input.end()); |
| 98 | } else if (input.find('\n') != std::string::npos) { |
| 99 | throw std::runtime_error("Input is not valid base64-encoded data"); |
| 100 | } |
| 101 | std::string decoded = decodeBase64(input); |
| 102 | auto buf = std::make_shared<DecodedBuffer>(std::move(decoded)); |
| 103 | return jsi::ArrayBuffer(rt, std::move(buf)); |
| 104 | } catch (const std::runtime_error& e) { |
| 105 | throw jsi::JSError(rt, e.what()); |
| 106 | } catch (...) { |
| 107 | throw jsi::JSError(rt, "unknown decoding error"); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | } |
nothing calls this directly
no test coverage detected