+ int status = 0, round = 0;
+ phpstr buffer;
+
+ *buf = NULL;
+ *len = 0;
+
+ phpstr_init_ex(&buffer, Z->avail_in, PHPSTR_INIT_PREALLOC);
+
+ do {
+ if (PHPSTR_NOMEM == phpstr_resize_ex(&buffer, buffer.size, 0, 1)) {
+ status = Z_MEM_ERROR;
+ } else {
+ Z->avail_out = buffer.free;
+ Z->next_out = (Bytef *) buffer.data + buffer.used;
+#if 0
+ fprintf(stderr, "\n%3d: %3d PRIOR: size=%7lu,\tfree=%7lu,\tused=%7lu,\tavail_in=%7lu,\tavail_out=%7lu\n", round, status, buffer.size, buffer.free, buffer.used, Z->avail_in, Z->avail_out);
+#endif
+ status = inflate(Z, flush);
+
+ buffer.used += buffer.free - Z->avail_out;
+ buffer.free = Z->avail_out;
+#if 0
+ fprintf(stderr, "%3d: %3d AFTER: size=%7lu,\tfree=%7lu,\tused=%7lu,\tavail_in=%7lu,\tavail_out=%7lu\n", round, status, buffer.size, buffer.free, buffer.used, Z->avail_in, Z->avail_out);
+#endif
+ HTTP_INFLATE_BUFFER_SIZE_ALIGN(buffer.size);
+ }
+ } while ((Z_BUF_ERROR == status || (Z_OK == status && Z->avail_in)) && ++round < HTTP_INFLATE_ROUNDS);
+
+ if (status == Z_OK || status == Z_STREAM_END) {
+ phpstr_shrink(&buffer);
+ phpstr_fix(&buffer);
+ *buf = buffer.data;
+ *len = buffer.used;
+ } else {
+ phpstr_dtor(&buffer);
+ }
+
+ return status;
+}
+/* }}} */
+
+/* {{{ STATUS http_encoding_deflate(int, char *, size_t, char **, size_t *) */
+PHP_HTTP_API STATUS _http_encoding_deflate(int flags, const char *data, size_t data_len, char **encoded, size_t *encoded_len ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
+{
+ int status, level, wbits, strategy;
+ z_stream Z;