-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcompressed_stream.cc
More file actions
75 lines (65 loc) · 2.24 KB
/
compressed_stream.cc
File metadata and controls
75 lines (65 loc) · 2.24 KB
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
// Copyright (c) 2014 The Trident Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This file is modified from `protobuf-zerocopy-compression':
// https://github.com/JohannesEbke/protobuf-zerocopy-compression
// Copyright (c) 2013, Johannes Ebke and Peter Waller. All rights reserved.
// Author: peter.waller@gmail.com (Peter Waller)
// Author: johannes@ebke.org (Johannes Ebke)
#include <trident/compressed_stream.h>
#include <trident/block_wrappers.h>
#include <trident/common.h>
#include <trident/gzip_stream.h>
namespace trident {
AbstractCompressedInputStream * get_compressed_input_stream(
ZeroCopyInputStream * istream, CompressType type) {
switch(type) {
case CompressTypeGzip:
return new GzipInputStream(istream, GzipInputStream::GZIP);
case CompressTypeZlib:
return new GzipInputStream(istream, GzipInputStream::ZLIB);
case CompressTypeSnappy:
#ifdef HAVE_SNAPPY
return new SnappyInputStream(istream);
#else
SCHECK(false);
#endif
case CompressTypeLZ4:
return new LZ4InputStream(istream);
default:
SCHECK(false);
}
return NULL;
}
AbstractCompressedOutputStream * get_compressed_output_stream(
ZeroCopyOutputStream * ostream, CompressType type, int level) {
switch (type) {
case CompressTypeGzip:
{
GzipOutputStream::Options o;
o.format = GzipOutputStream::GZIP;
o.compression_level = level;
return new GzipOutputStream(ostream, o);
}
case CompressTypeZlib:
{
GzipOutputStream::Options o;
o.format = GzipOutputStream::ZLIB;
o.compression_level = level;
return new GzipOutputStream(ostream, o);
}
case CompressTypeSnappy:
#ifdef HAVE_SNAPPY
return new SnappyOutputStream(ostream);
#else
SCHECK(false);
#endif
case CompressTypeLZ4:
return new LZ4OutputStream(ostream);
default:
SCHECK(false);
}
return NULL;
}
} // namespace trident
/* vim: set ts=4 sw=4 sts=4 tw=100 */