- /* LSB */
- trailer[0] = (char) (crc & 0xFF);
- trailer[1] = (char) ((crc >> 8) & 0xFF);
- trailer[2] = (char) ((crc >> 16) & 0xFF);
- trailer[3] = (char) ((crc >> 24) & 0xFF);
- trailer[4] = (char) ((Z->total_in) & 0xFF);
- trailer[5] = (char) ((Z->total_in >> 8) & 0xFF);
- trailer[6] = (char) ((Z->total_in >> 16) & 0xFF);
- trailer[7] = (char) ((Z->total_in >> 24) & 0xFF);
+ 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);
+ }