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