Refactor to work on Linux / Unix, fix some compiler errors.

CMakeLists was also modified to make this work, but its scuffed
and i will hold on to that for a while longer
This commit is contained in:
Lion Kortlepel
2020-11-01 02:00:27 +01:00
parent 02fbe72eed
commit 8bc35fb82e
18 changed files with 254 additions and 41 deletions

View File

@@ -3,11 +3,15 @@
///
#include "Zlib/zlib.h"
#include <iostream>
#include <cstring>
#include <algorithm>
#include <array>
#define Biggest 30000
std::string Comp(std::string Data){
char*C = new char[Biggest];
memset(C, 0, Biggest);
std::array<char, Biggest> C;
// obsolete
C.fill(0);
z_stream defstream;
defstream.zalloc = Z_NULL;
defstream.zfree = Z_NULL;
@@ -15,20 +19,20 @@ std::string Comp(std::string Data){
defstream.avail_in = (uInt)Data.length();
defstream.next_in = (Bytef *)&Data[0];
defstream.avail_out = Biggest;
defstream.next_out = reinterpret_cast<Bytef *>(C);
defstream.next_out = reinterpret_cast<Bytef *>(C.data());
deflateInit(&defstream, Z_BEST_COMPRESSION);
deflate(&defstream, Z_SYNC_FLUSH);
deflate(&defstream, Z_FINISH);
deflateEnd(&defstream);
int TO = defstream.total_out;
std::string Ret(TO,0);
memcpy_s(&Ret[0],TO,C,TO);
delete [] C;
std::copy_n(C.begin(), TO, Ret.begin());
return Ret;
}
std::string DeComp(std::string Compressed){
char*C = new char[Biggest];
memset(C, 0, Biggest);
std::array<char, Biggest> C;
// not needed
C.fill(0);
z_stream infstream;
infstream.zalloc = Z_NULL;
infstream.zfree = Z_NULL;
@@ -36,14 +40,13 @@ std::string DeComp(std::string Compressed){
infstream.avail_in = Biggest;
infstream.next_in = (Bytef *)(&Compressed[0]);
infstream.avail_out = Biggest;
infstream.next_out = (Bytef *)(C);
infstream.next_out = (Bytef *)(C.data());
inflateInit(&infstream);
inflate(&infstream, Z_SYNC_FLUSH);
inflate(&infstream, Z_FINISH);
inflateEnd(&infstream);
int TO = infstream.total_out;
std::string Ret(TO,0);
memcpy_s(&Ret[0],TO,C,TO);
delete [] C;
std::copy_n(C.begin(), TO, Ret.begin());
return Ret;
}
}