Rewrite
This commit is contained in:
Anonymous275
2020-08-21 20:57:41 +03:00
parent 5d6f2b93b2
commit ccdbc51b30
53 changed files with 2150 additions and 1626 deletions

View File

@@ -1,59 +1,49 @@
///
/// Created by Anonymous275 on 4/23/2020
/// Created by Anonymous275 on 7/15/2020
///
#include <string>
#include "Zlib/zlib.h"
#include <iostream>
#include "include/zlib.h"
void Print(const std::string&MSG){
//std::cout << MSG << std::endl;
}
std::string Compress(const std::string&Data){
std::string b;
b.resize(Data.length());
#define Biggest 30000
std::string Comp(std::string Data){
char*C = new char[Biggest];
memset(C, 0, Biggest);
z_stream defstream;
defstream.zalloc = Z_NULL;
defstream.zfree = Z_NULL;
defstream.opaque = Z_NULL;
defstream.avail_in = (uInt)Data.length()+1;
defstream.avail_in = (uInt)Data.length();
defstream.next_in = (Bytef *)&Data[0];
defstream.avail_out = (uInt)b.size();
defstream.next_out = (Bytef *)&b[0];
defstream.avail_out = Biggest;
defstream.next_out = reinterpret_cast<Bytef *>(C);
deflateInit(&defstream, Z_BEST_COMPRESSION);
deflate(&defstream, Z_SYNC_FLUSH);
deflate(&defstream, Z_FINISH);
deflateEnd(&defstream);
for(int i = int(b.length())-1;i >= 0;i--){
if(b.at(i) != '\0'){
b.resize(i);
break;
}
}
return b;
int TO = defstream.total_out;
std::string Ret(TO,0);
memcpy_s(&Ret[0],TO,C,TO);
delete [] C;
return Ret;
}
std::string Decompress(const std::string&Data)
{
std::string c;
c.resize(Data.size()*5);
std::string DeComp(std::string Compressed){
char*C = new char[Biggest];
memset(C, 0, Biggest);
z_stream infstream;
infstream.zalloc = Z_NULL;
infstream.zfree = Z_NULL;
infstream.opaque = Z_NULL;
infstream.avail_in = (uInt)(Data.c_str());
infstream.next_in = (Bytef *)&Data[0];
infstream.avail_out = (uInt)c.size();
infstream.next_out = (Bytef *)&c[0];
infstream.avail_in = Biggest;
infstream.next_in = (Bytef *)(&Compressed[0]);
infstream.avail_out = Biggest;
infstream.next_out = (Bytef *)(C);
inflateInit(&infstream);
inflate(&infstream, Z_NO_FLUSH);
inflate(&infstream, Z_SYNC_FLUSH);
inflate(&infstream, Z_FINISH);
inflateEnd(&infstream);
for(int i = int(c.length())-1;i >= 0;i--){
if(c.at(i) != '\0'){
c.resize(i+1);
break;
}
}
return c;
int TO = infstream.total_out;
std::string Ret(TO,0);
memcpy_s(&Ret[0],TO,C,TO);
delete [] C;
return Ret;
}