-
Notifications
You must be signed in to change notification settings - Fork 46
Open
Description
Hi @powturbo
Thanks for your great work!
Recently, I discovered that when using this library to encode image files, there are some strange characters appearing at the end. Printing them out shows 'NULL' or just some patterns. ( Like ”7mlbMjdKxLobZAOx6jFekoqMbHg==�#��+Z��8Z�s)��k_H���pd�?���Ծ ” "Px/wA7sn4uWWf/AAj/AA3/ALQooor0Yg==NULLNULLNULL"
My code:
std::ifstream ifs(file_path, std::ios::binary);
if (!ifs.is_open()) {
std::cerr << "Unable to open file: " << file_path << std::endl;
}
ifs.seekg(0, std::ios::end);
auto size = ifs.tellg();
ifs.seekg(0, std::ios::beg);
// Read the file content into a char buffer
auto buf = new unsigned char[size];
ifs.read((char *) buf, size);
//use turbobase64
auto outsize = tb64enclen(size);
auto out = new uint8_t[outsize];
size_t num_enc = tb64enc(buf, size, out); //error handle
out[num_enc] = 0;
std::string str_encode(out, out + num_enc);
std::cout << str_encode << std::endl;I'm confused. Shouldn't the size of a string converted to Base64 be fixed? Why are there unknown characters appearing
Metadata
Metadata
Assignees
Labels
No labels