@@ -213,19 +213,21 @@ struct InflationStream {
213213 std::optional<std::string_view> inflate (ZlibContext *zlibContext, std::string_view compressed, size_t maxPayloadLength, bool reset) {
214214
215215#ifdef UWS_USE_LIBDEFLATE
216- /* Try fast path first (assuming single DEFLATE block) */
217- size_t written = 0 , consumed;
218- zlibContext->dynamicInflationBuffer .clear ();
219- zlibContext->dynamicInflationBuffer .reserve (maxPayloadLength);
220-
221- ((char *)compressed.data ())[0 ] |= 0x1 ; // BFINAL = 1
222- libdeflate_result res = libdeflate_deflate_decompress_ex (zlibContext->decompressor , compressed.data (), compressed.length (), zlibContext->dynamicInflationBuffer .data (), maxPayloadLength, &consumed, &written);
223-
224- if (res == 0 && consumed == compressed.length ()) {
225- return std::string_view (zlibContext->dynamicInflationBuffer .data (), written);
226- } else {
227- /* We can only end up here if the first DEFLATE block was not the last, so mark it as such */
228- ((char *)compressed.data ())[0 ] &= ~0x1 ; // BFINAL = 0
216+ if (reset) {
217+ /* Try fast path first (assuming single DEFLATE block and shared compressor aka reset = true) */
218+ size_t written = 0 , consumed;
219+ zlibContext->dynamicInflationBuffer .clear ();
220+ zlibContext->dynamicInflationBuffer .reserve (maxPayloadLength);
221+
222+ ((char *)compressed.data ())[0 ] |= 0x1 ; // BFINAL = 1
223+ libdeflate_result res = libdeflate_deflate_decompress_ex (zlibContext->decompressor , compressed.data (), compressed.length (), zlibContext->dynamicInflationBuffer .data (), maxPayloadLength, &consumed, &written);
224+
225+ if (res == 0 && consumed == compressed.length ()) {
226+ return std::string_view (zlibContext->dynamicInflationBuffer .data (), written);
227+ } else {
228+ /* We can only end up here if the first DEFLATE block was not the last, so mark it as such */
229+ ((char *)compressed.data ())[0 ] &= ~0x1 ; // BFINAL = 0
230+ }
229231 }
230232#endif
231233
0 commit comments