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

Method consume

src/tscpp/api/GzipInflateTransformation.cc:85–131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83}
84
85void
86GzipInflateTransformation::consume(std::string_view data)
87{
88 if (data.size() == 0) {
89 return;
90 }
91
92 if (!state_->z_stream_initialized_) {
93 LOG_ERROR("Unable to inflate output because the z_stream was not initialized.");
94 return;
95 }
96
97 int err = Z_OK;
98 int iteration = 0;
99 int inflate_block_size = INFLATE_SCALE_FACTOR * data.size();
100 vector<char> buffer(inflate_block_size);
101
102 // Setup the compressed input
103 state_->z_stream_.next_in = reinterpret_cast<unsigned char *>(const_cast<char *>(data.data()));
104 state_->z_stream_.avail_in = data.length();
105
106 // Loop while we have more data to inflate
107 while (state_->z_stream_.avail_in > 0 && err != Z_STREAM_END) {
108 LOG_DEBUG("Iteration %d: Gzip has %d bytes to inflate", ++iteration, state_->z_stream_.avail_in);
109
110 // Setup where the decompressed output will go
111 // next_out needs to be set to nullptr before we return since it points to a local buffer
112 // coverity[WRAPPER_ESCAPE: FALSE]
113 state_->z_stream_.next_out = reinterpret_cast<unsigned char *>(&buffer[0]);
114 state_->z_stream_.avail_out = inflate_block_size;
115
116 // Uncompress the data
117 err = inflate(&state_->z_stream_, Z_SYNC_FLUSH);
118
119 if (err != Z_OK && err != Z_STREAM_END) {
120 LOG_ERROR("Iteration %d: Inflate failed with error '%d'", iteration, err);
121 state_->z_stream_.next_out = nullptr;
122 return;
123 }
124
125 LOG_DEBUG("Iteration %d: Gzip inflated a total of %d bytes, producingOutput...", iteration,
126 (inflate_block_size - state_->z_stream_.avail_out));
127 produce(std::string_view(&buffer[0], (inflate_block_size - state_->z_stream_.avail_out)));
128 state_->bytes_produced_ += (inflate_block_size - state_->z_stream_.avail_out);
129 }
130 state_->z_stream_.next_out = nullptr;
131}
132
133void
134GzipInflateTransformation::handleInputComplete()

Calls 3

sizeMethod · 0.45
dataMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected