Wittyshare  0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WsDecompressor.cpp
Go to the documentation of this file.
1 /*
2  *
3  * Filename: WsDecompressor.cpp
4  *
5  * Description:
6  *
7  * Created: 07/25/2012 09:29:01 AM
8  *
9  * Author: Benoit Daccache, ben.daccache@gmail.com
10  *
11  */
12 
13 #include "WsDecompressor.h"
14 
15 #include <Include/WsGlobalConfig.h>
16 #include <Logger/WsLogger.h>
17 
18 #include <stdio.h>
19 #include <zlib.h>
20 
21 
22 using namespace std;
23 
24 long WsDecompressor::decompress(const char* data, size_t size, string& uncompressedData)
25 {
26  uLongf unCompSize = 200 * size;
27  char* to = new char[unCompSize];
28  if (uncompress((Bytef*)to, &unCompSize, (const Bytef*)data, size) != Z_OK) {
29  LOG(ERROR) << "WsDecompressor :: Decompression failed";
30  return ErrorCode::Failure;
31  }
32  uncompressedData = string(to, unCompSize);
33  delete[] to;
34  return unCompSize;
35 }
36 
const int Failure
#define LOG
Definition: WsLogger.h:22
long decompress(const char *data, size_t size, std::string &uncompressedData)
decompress the input data and store result in uncompressedData
#define ERROR
Definition: WsLogger.h:42