- return enbrotli_flush_ex(s, BROTLI_OPERATION_FINISH, encoded, encoded_len);
+ ZEND_RESULT_CODE rc;
+
+ do {
+ rc = enbrotli_flush_ex(s, BROTLI_OPERATION_FINISH, encoded, encoded_len);
+ } while (SUCCESS == rc && !BrotliEncoderIsFinished(s->ctx));
+
+ return rc;