Wittyshare
0.2
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Pages
wscore
src
Compression
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
}
WsLogger.h
ErrorCode::Failure
const int Failure
Definition:
WsGlobalConfig.h:21
WsCompressor.h
LOG
#define LOG
Definition:
WsLogger.h:22
WsGlobalConfig.h
WsCompressor::compress
long compress(const std::string &data, char **compressedData)
compress the input string (data) and puts it in compressedData.
Definition:
WsCompressor.cpp:22
ERROR
#define ERROR
Definition:
WsLogger.h:42
Generated on Wed Apr 23 2014 14:00:10 for Wittyshare by
1.8.6