MCPcopy Create free account
hub / github.com/apache/trafficserver / data_alloc

Function data_alloc

plugins/compress/compress.cc:139–200  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

137} // namespace
138
139static Data *
140data_alloc(int compression_type, int compression_algorithms)
141{
142 Data *data;
143 int err;
144
145 data = static_cast<Data *>(TSmalloc(sizeof(Data)));
146 data->downstream_vio = nullptr;
147 data->downstream_buffer = nullptr;
148 data->downstream_reader = nullptr;
149 data->downstream_length = 0;
150 data->state = transform_state_initialized;
151 data->compression_type = compression_type;
152 data->compression_algorithms = compression_algorithms;
153 data->zstrm.next_in = Z_NULL;
154 data->zstrm.avail_in = 0;
155 data->zstrm.total_in = 0;
156 data->zstrm.next_out = Z_NULL;
157 data->zstrm.avail_out = 0;
158 data->zstrm.total_out = 0;
159 data->zstrm.zalloc = gzip_alloc;
160 data->zstrm.zfree = gzip_free;
161 data->zstrm.opaque = (voidpf) nullptr;
162 data->zstrm.data_type = Z_ASCII;
163
164 int window_bits = WINDOW_BITS_GZIP;
165 if (compression_type & COMPRESSION_TYPE_DEFLATE) {
166 window_bits = WINDOW_BITS_DEFLATE;
167 }
168
169 err = deflateInit2(&data->zstrm, ZLIB_COMPRESSION_LEVEL, Z_DEFLATED, window_bits, ZLIB_MEMLEVEL, Z_DEFAULT_STRATEGY);
170
171 if (err != Z_OK) {
172 fatal("gzip-transform: ERROR: deflateInit (%d)!", err);
173 }
174
175 if (dictionary) {
176 err = deflateSetDictionary(&data->zstrm, reinterpret_cast<const Bytef *>(dictionary), strlen(dictionary));
177 if (err != Z_OK) {
178 fatal("gzip-transform: ERROR: deflateSetDictionary (%d)!", err);
179 }
180 }
181#if HAVE_BROTLI_ENCODE_H
182 data->bstrm.br = nullptr;
183 if (compression_type & COMPRESSION_TYPE_BROTLI) {
184 debug("brotli compression. Create Brotli Encoder Instance.");
185 data->bstrm.br = BrotliEncoderCreateInstance(nullptr, nullptr, nullptr);
186 if (!data->bstrm.br) {
187 fatal("Brotli Encoder Instance Failed");
188 }
189 BrotliEncoderSetParameter(data->bstrm.br, BROTLI_PARAM_QUALITY, BROTLI_COMPRESSION_LEVEL);
190 BrotliEncoderSetParameter(data->bstrm.br, BROTLI_PARAM_LGWIN, BROTLI_LGW);
191 data->bstrm.next_in = nullptr;
192 data->bstrm.avail_in = 0;
193 data->bstrm.total_in = 0;
194 data->bstrm.next_out = nullptr;
195 data->bstrm.avail_out = 0;
196 data->bstrm.total_out = 0;

Callers 1

compress_transform_addFunction · 0.85

Calls 1

TSmallocFunction · 0.85

Tested by

no test coverage detected