Created
August 7, 2018 11:56
-
-
Save nna774/3e9bf18b211123dcd91711d0c8484842 to your computer and use it in GitHub Desktop.
This file contains 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
#include <algorithm> | |
#include <memory> | |
#include "deflate.h" | |
#define MINIZ_NO_ZLIB_COMPATIBLE_NAMES | |
#include "miniz.c" | |
// using std::begin; | |
// using std::end; | |
namespace Deflate { | |
std::vector<Byte> compress(std::vector<Byte> const& src) { | |
unsigned long size = mz_compressBound(src.size()); | |
std::unique_ptr<Byte> buf{new Byte[size]}; | |
int status = mz_compress(buf.get(), &size, src.data(), src.size()); | |
if (status != MZ_OK) { | |
return {}; | |
} | |
std::vector<Byte> v(size); | |
std::copy_n(buf.get(), size, begin(v)); | |
return v; | |
} | |
std::vector<Byte> decompress(std::vector<Byte> const& src) { | |
std::vector<Byte> v; | |
unsigned long size = src.size() * 100; // | |
Byte *buf = new Byte[size]; | |
int status = mz_uncompress(buf, &size, src.data(), src.size()); | |
if (status != MZ_OK) { | |
return v; | |
} | |
for(unsigned long i{0}; i < size; ++i) { | |
v.push_back(buf[i]); | |
} | |
return v; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment