+static int flush_zlib_buffer(deflate_ctx *ctx, deflate_filter_config *c,
+ struct apr_bucket_alloc_t *bucket_alloc,
+ int flush)
+{
+ int zRC;
+ int done = 0;
+ unsigned int deflate_len;
+ apr_bucket *b;
+
+ for (;;) {
+ deflate_len = c->bufferSize - ctx->stream.avail_out;
+
+ if (deflate_len != 0) {
+ b = apr_bucket_heap_create((char *)ctx->buffer,
+ deflate_len, NULL,
+ bucket_alloc);
+ APR_BRIGADE_INSERT_TAIL(ctx->bb, b);
+ ctx->stream.next_out = ctx->buffer;
+ ctx->stream.avail_out = c->bufferSize;
+ }
+
+ if (done)
+ break;
+
+ zRC = deflate(&ctx->stream, flush);
+
+ if (deflate_len == 0 && zRC == Z_BUF_ERROR)
+ zRC = Z_OK;
+
+ done = (ctx->stream.avail_out != 0 || zRC == Z_STREAM_END);
+
+ if (zRC != Z_OK && zRC != Z_STREAM_END)
+ break;
+ }
+ return zRC;
+}
+