Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::string Decompress(char* Data, int Size)
- {
- std::string Result;
- z_stream zs;
- std::memset(&zs, 0, sizeof(zs));
- if (inflateInit(&zs) != Z_OK)
- throw(std::runtime_error("inflateInit failed while decompressing."));
- zs.next_in = (Bytef*)Data;
- zs.avail_in = Size;
- int Success = 0;
- std::vector<char> Temp(32768);
- do {
- zs.next_out = reinterpret_cast<Bytef*>(&Temp[0]);
- zs.avail_out = Temp.size();
- Success = inflate(&zs, 0);
- if (Result.size() < zs.total_out)
- {
- Result.append(Temp.data(), zs.total_out - Result.size());
- }
- } while (Success == Z_OK);
- inflateEnd(&zs);
- if (Success != Z_STREAM_END)
- {
- std::ostringstream OS;
- OS << "Exception during zlib decompression: (" << Success << ")" << zs.msg;
- throw(std::runtime_error(OS.str());
- }
- return Result;
- }
Advertisement
Add Comment
Please, Sign In to add comment