This source file includes following definitions.
- opal_compress_zlib_module_init
- opal_compress_zlib_module_finalize
- opal_compress_zlib_compress_block
- opal_compress_zlib_uncompress_block
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 #include "opal_config.h"
19
20 #include <string.h>
21 #include <sys/types.h>
22 #include <sys/wait.h>
23 #include <sys/stat.h>
24 #if HAVE_UNISTD_H
25 #include <unistd.h>
26 #endif
27 #include <zlib.h>
28
29 #include "opal/util/opal_environ.h"
30 #include "opal/util/output.h"
31 #include "opal/util/argv.h"
32 #include "opal/util/opal_environ.h"
33 #include "opal/util/printf.h"
34
35 #include "opal/constants.h"
36 #include "opal/util/basename.h"
37
38 #include "opal/mca/compress/compress.h"
39 #include "opal/mca/compress/base/base.h"
40
41 #include "compress_zlib.h"
42
43 int opal_compress_zlib_module_init(void)
44 {
45 return OPAL_SUCCESS;
46 }
47
48 int opal_compress_zlib_module_finalize(void)
49 {
50 return OPAL_SUCCESS;
51 }
52
53 bool opal_compress_zlib_compress_block(uint8_t *inbytes,
54 size_t inlen,
55 uint8_t **outbytes,
56 size_t *olen)
57 {
58 z_stream strm;
59 size_t len;
60 uint8_t *tmp;
61
62 if (inlen < opal_compress_base.compress_limit) {
63 return false;
64 }
65 opal_output_verbose(2, opal_compress_base_framework.framework_output,
66 "COMPRESSING");
67
68
69 *outbytes = NULL;
70 *olen = 0;
71
72
73 memset (&strm, 0, sizeof (strm));
74 deflateInit (&strm, 9);
75
76
77 len = deflateBound(&strm, inlen);
78 if (NULL == (tmp = (uint8_t*)malloc(len))) {
79 return false;
80 }
81 strm.next_in = inbytes;
82 strm.avail_in = inlen;
83
84
85
86 strm.avail_out = len;
87 strm.next_out = tmp;
88
89 deflate (&strm, Z_FINISH);
90 deflateEnd (&strm);
91
92 *outbytes = tmp;
93 *olen = len - strm.avail_out;
94 opal_output_verbose(2, opal_compress_base_framework.framework_output,
95 "\tINSIZE %d OUTSIZE %d", (int)inlen, (int)*olen);
96 return true;
97 }
98
99 bool opal_compress_zlib_uncompress_block(uint8_t **outbytes, size_t olen,
100 uint8_t *inbytes, size_t len)
101 {
102 uint8_t *dest;
103 z_stream strm;
104
105
106 *outbytes = NULL;
107 opal_output_verbose(2, opal_compress_base_framework.framework_output, "DECOMPRESS");
108
109
110 dest = (uint8_t*)malloc(olen);
111 if (NULL == dest) {
112 return false;
113 }
114
115 memset (&strm, 0, sizeof (strm));
116 if (Z_OK != inflateInit(&strm)) {
117 free(dest);
118 return false;
119 }
120 strm.avail_in = len;
121 strm.next_in = inbytes;
122 strm.avail_out = olen;
123 strm.next_out = dest;
124
125 if (Z_STREAM_END != inflate (&strm, Z_FINISH)) {
126 opal_output(0, "\tDECOMPRESS FAILED: %s", strm.msg);
127 }
128 inflateEnd (&strm);
129 *outbytes = dest;
130 opal_output_verbose(2, opal_compress_base_framework.framework_output,
131 "\tINSIZE: %d OUTSIZE %d", (int)len, (int)olen);
132 return true;
133 }