-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathzstd_helper.cpp
More file actions
37 lines (26 loc) · 850 Bytes
/
Copy pathzstd_helper.cpp
File metadata and controls
37 lines (26 loc) · 850 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "zstd_helper.hpp"
#include <iostream>
#include <zstd.h>
using namespace std;
namespace zstd
{
string decompress(const string &compressed)
{
const unsigned long long frameSize = ZSTD_getFrameContentSize(compressed.c_str(), compressed.size());
if (frameSize == ZSTD_CONTENTSIZE_ERROR or frameSize == ZSTD_CONTENTSIZE_UNKNOWN)
{
cerr << "Zstd decompression failed, missing frame content size" << endl;
return "";
}
char *dstBuffer = new char[frameSize];
const size_t decompressedSize = ZSTD_decompress(dstBuffer, frameSize, compressed.c_str(), compressed.size());
if (ZSTD_isError(decompressedSize))
{
cerr << "Zstd compression failed" << endl;
return "";
}
const string ret(dstBuffer, dstBuffer + decompressedSize);
delete[] dstBuffer;
return ret;
}
}