-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGzip.hpp
132 lines (93 loc) · 2.32 KB
/
Gzip.hpp
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#ifndef _GZIP_HPP_
#define _GZIP_HPP_
/*
Name
Gzip
Authors
[ETL] Eun T. Leem ([email protected])
Description
Last Modified Date
Feb 19, 2015
History
November 23, 2013
Created
ToDos
02-19-2015
Add Config and Option not to use memory pool.
Milestones
1.0
Learning Resources
http://
Copyright (c) All rights reserved to LIFEINO.
*/
#ifdef _DEBUG
#undef _DEBUG
#endif
#define _DEBUG true
#include "liolib/Debug.hpp"
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include "liolib/MemoryPool.hpp"
#include "liolib/DataBlock.hpp" // DataBlock
#include "include/zlib.h"
namespace lio {
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
# include <fcntl.h>
# include <io.h>
# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
#else
# define SET_BINARY_MODE(file)
#endif
class Gzip {
public:
// ******** Exception Declaration *********
enum class ExceptionType : std::uint8_t {
GENERAL,
COMPRESSION_FAIL,
DECOMPRESSION_FAIL
};
#define GZIP_EXCEPTION_MESSAGES \
"Gzip Exception has been thrown.", \
"Failed to compress.", \
"Failed to decompress"
class Exception : public std::exception {
public:
Exception (ExceptionType exceptionType = ExceptionType::GENERAL);
virtual const char* what() const noexcept;
virtual const ExceptionType type() const noexcept;
private:
const ExceptionType exceptionType_;
static const char* const exceptionMessages_[];
};
// ******** Exception Declaration END*********
struct Config {
Config() :
useMemoryPool(false),
memoryPoolSize(1024 * 1024 * 3)
{
}
bool useMemoryPool;
size_t memoryPoolSize;
};
Gzip(Config config = Config());
~Gzip();
DataBlock<> Compress(const void* source, size_t length, int level = Z_DEFAULT_COMPRESSION);
DataBlock<> Decompress(const void* source, size_t length);
ssize_t Compress(const void* source, size_t length, char* dest, size_t maxSize,
int level = Z_DEFAULT_COMPRESSION);
ssize_t Decompress(const void* source, size_t length, char* dest, size_t maxSize);
protected:
private:
Config config_;
MemoryPool* mp_;
static
const size_t CHUNK_SIZE;
static
const int WINDOWS_BITS;
static
const int GZIP_ENCODING;
};
}
#endif