New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
create higher level base64 functions #377
Comments
I was thinking a little about API. My generic proposal is providing a convenient wrapper that would work incrementally. I mean: user provides partial data (like input buffer when reading from file) and output buffer of fixed size. Using for decoding would be something like: auto decoder = Base64Decoder::new();
std::string input;
input.resize(32 * 1024);
std::string output;
output.resize(16 * 1024);
while (/**/) {
// read a few kilobytes data from into `input`
const size_t bytes_stored = decoder.decode(input.data(), input.size(), output.data(), output.size());
// bytes_stored will never be greater than output.size()
write (output.data(), bytes_stored)
if input file reached EOF {
while (decoder.pending_output()) {
const size_t bytes_stored = decoder.flush(output.data(), output.size());
write (output.data(), bytes)
}
}
} Of course this flexibility is at cost of performance, but my gut feeling is that if somebody want to process data in chunks, than problem is likely I/O bound. |
Another thing for base64 encoding - it would be practical if we allowed wrapping output, for instance:
|
@WojciechMula I'm pinging you later today as I have a major upgrade to the base64 support, with a slightly improved API. |
Please see #382 where the base64 API was slightly extended (i.e., we have |
We should also provide base64_to_binary(const char* input) -> std::vector<uint8_t>, that does calculation of safe size and allocate memory internally. Or maybe something like base_to_binary(const char* input, cont: &Container) and static_assert that the Container has method resize. (credit: @WojciechMula)
The text was updated successfully, but these errors were encountered: