diff --git a/include/string.hpp b/include/string.hpp index 6ebf7887..70e71cfa 100644 --- a/include/string.hpp +++ b/include/string.hpp @@ -67,8 +67,7 @@ https://en.wikipedia.org/wiki/Base64 std::string toBase64(const uint8_t* data, size_t dataLen); std::string toBase64(const std::vector& data); /** Converts a Base64-encoded string to a byte array. -`outLen` is set to the length of the byte array. -If non-NULL, caller must delete[] the result. +Throws std::runtime_error if string is invalid. */ std::vector fromBase64(const std::string& str); @@ -77,6 +76,8 @@ std::vector fromBase64(const std::string& str); std::vector compress(const uint8_t* data, size_t dataLen); std::vector compress(const std::vector& data); /** Uncompress bytes with zlib. +Before calling this function, set `dataLen` to the capacity of `data`. +After returning, `dataLen` is set to the number of bytes written. Unfortunately the output buffer cannot be computed from the compressed data, so you may need to hard-code the maximum expected size. */ void uncompress(const uint8_t* compressed, size_t compressedLen, uint8_t* data, size_t* dataLen); diff --git a/src/string.cpp b/src/string.cpp index 80eac59f..4de82dd0 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -158,7 +158,7 @@ float fuzzyScore(const std::string& s, const std::string& query) { std::string toBase64(const uint8_t* data, size_t dataLen) { static const char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - size_t numBlocks = size_t((dataLen + 2) / 3); + size_t numBlocks = (dataLen + 2) / 3; size_t strLen = numBlocks * 4; std::string str; str.reserve(strLen);