void HttpHandler::BrotliFlush() { do { this->brotli_available_in = 0; if (!BrotliEncoderCompressStream(this->brotli, BROTLI_OPERATION_FINISH, &this->brotli_available_in, &this->brotli_next_in, &this->brotli_available_out, &this->brotli_next_out, NULL)) { std::cerr << "failed to compress data" << std::endl; return; } this->response.write(reinterpret_cast<const char*>(this->brotli_out), COMPRESSION_BUFFER_SIZE - this->brotli_available_out); this->brotli_available_out = COMPRESSION_BUFFER_SIZE; this->brotli_next_out = this->brotli_out; } while(BrotliEncoderHasMoreOutput(this->brotli)); }
static SquashStatus squash_brotli_process_stream (SquashStream* stream, SquashOperation operation) { SquashBrotliStream* s = (SquashBrotliStream*) stream; if (stream->stream_type == SQUASH_STREAM_COMPRESS) { const int be_ret = BrotliEncoderCompressStream(s->ctx.encoder, squash_brotli_encoder_operation_from_squash_operation(operation), &(stream->avail_in), &(stream->next_in), &(stream->avail_out), &(stream->next_out), NULL); if (SQUASH_UNLIKELY(be_ret != 1)) return squash_error (SQUASH_FAILED); else if (stream->avail_in != 0 || BrotliEncoderHasMoreOutput(s->ctx.encoder)) return SQUASH_PROCESSING; else return SQUASH_OK; } else if (stream->stream_type == SQUASH_STREAM_DECOMPRESS) { const BrotliResult bd_ret = BrotliDecompressStream(&(stream->avail_in), &(stream->next_in), &(stream->avail_out), &(stream->next_out), NULL, s->ctx.decoder); switch (bd_ret) { case BROTLI_RESULT_SUCCESS: return SQUASH_OK; case BROTLI_RESULT_NEEDS_MORE_INPUT: return SQUASH_OK; case BROTLI_RESULT_NEEDS_MORE_OUTPUT: return SQUASH_PROCESSING; case BROTLI_RESULT_ERROR: return SQUASH_FAILED; } if (SQUASH_UNLIKELY(bd_ret != BROTLI_RESULT_SUCCESS)) return squash_error (SQUASH_FAILED); } else { squash_assert_unreachable (); } squash_assert_unreachable (); }