Created
April 28, 2019 23:19
-
-
Save MagnificentPako/ffa21878ce28b345fd5049acc455d363 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define CPPHTTPLIB_OPENSSL_SUPPORT | |
#include <emojicode/runtime/Runtime.h> | |
#include <emojicode/s/Data.h> | |
#include <string> | |
#include <iostream> | |
#include <sstream> | |
#include <vector> | |
#include <zstr.hpp> | |
extern "C" s::Data* decompress(s::Data* data) { | |
std::stringstream ss; | |
s::Data* output = s::Data::init(); | |
std::vector<char> chars; | |
for(int i = 0; i < data->count; i++) { | |
ss << data->data[i]; | |
} | |
zstr::istream is(ss); | |
const std::streamsize buff_size = 1 << 16; | |
char* buff = new char[buff_size]; | |
while(true) { | |
is.read(buff, buff_size); | |
std::streamsize cnt = is.gcount(); | |
if(cnt == 0) break; | |
for(int i = 0; i < cnt; i++) { | |
chars.push_back(buff[i]); | |
} | |
} | |
auto bytes = runtime::allocate<runtime::Byte>(chars.size()); | |
char* b = reinterpret_cast<char *>(bytes.get()); | |
output->count = chars.size(); | |
memcpy(chars.data(), b, chars.size() * sizeof(char)); | |
delete [] buff; | |
return output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment