-
Notifications
You must be signed in to change notification settings - Fork 4
/
compressed_stream.cc
56 lines (52 loc) · 1.53 KB
/
compressed_stream.cc
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
#include <compressed_stream.h>
#include <gzip_stream.h>
#include <block_wrappers.h>
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
namespace zerocc {
AbstractCompressedInputStream * get_compressed_input_stream(ZeroCopyInputStream * istream, CompressionType t) {
switch(t) {
case ZLIB:
return new GzipInputStream(istream, GzipInputStream::ZLIB);
case GZIP:
return new GzipInputStream(istream, GzipInputStream::GZIP);
case SNAPPY:
#ifdef HAVE_SNAPPY
return new SnappyInputStream(istream);
#else
return NULL;
#endif
case LZ4:
return new LZ4InputStream(istream);
}
return NULL;
}
AbstractCompressedOutputStream * get_compressed_output_stream(ZeroCopyOutputStream * ostream, CompressionType t, int level) {
switch (t) {
case ZLIB:
{
GzipOutputStream::Options o;
o.format = GzipOutputStream::ZLIB;
o.compression_level = level;
return new GzipOutputStream(ostream, o);
}
case GZIP:
{
GzipOutputStream::Options o;
o.format = GzipOutputStream::GZIP;
o.compression_level = level;
return new GzipOutputStream(ostream, o);
}
case SNAPPY:
#ifdef HAVE_SNAPPY
return new SnappyOutputStream(ostream);
#else
return NULL;
#endif
case LZ4:
return new LZ4OutputStream(ostream);
}
return NULL;
}
}; // namespace zerocc