do {
Z.avail_out = (buffer.free -= Z.total_out - buffer.used);
- Z.next_out = buffer.data + (buffer.used = Z.total_out);
+ Z.next_out = (Bytef *) buffer.data + (buffer.used = Z.total_out);
status = inflate(&Z, Z_NO_FLUSH);
} while (Z_OK == status);
} while (Z_BUF_ERROR == status && ++max < HTTP_ENCODING_MAXTRY);
/* append input to our buffer */
phpstr_append(PHPSTR(s->stream.opaque), data, data_len);
- s->stream.next_in = PHPSTR_VAL(s->stream.opaque);
+ s->stream.next_in = (Bytef *) PHPSTR_VAL(s->stream.opaque);
s->stream.avail_in = PHPSTR_LEN(s->stream.opaque);
/* deflate */
s->stream.avail_out = *encoded_len = HTTP_ENCODING_BUFLEN(data_len);
- s->stream.next_out = *encoded = emalloc(*encoded_len);
+ s->stream.next_out = (Bytef *) *encoded = emalloc(*encoded_len);
switch (status = deflate(&s->stream, Z_NO_FLUSH))
{
*decoded = erealloc(*decoded, *decoded_len);
retry_raw_inflate:
- s->stream.next_in = PHPSTR_VAL(s->stream.opaque);
+ s->stream.next_in = (Bytef *) PHPSTR_VAL(s->stream.opaque);
s->stream.avail_in = PHPSTR_LEN(s->stream.opaque);
- s->stream.next_out = *decoded;
+ s->stream.next_out = (Bytef *) *decoded;
s->stream.avail_out = *decoded_len;
switch (status = inflate(&s->stream, Z_NO_FLUSH))
s->stream.avail_in = 0;
s->stream.next_in = NULL;
s->stream.avail_out = *encoded_len = 0x800;
- s->stream.next_out = *encoded = emalloc(*encoded_len);
+ s->stream.next_out = (Bytef *) *encoded = emalloc(*encoded_len);
switch (status = deflate(&s->stream, Z_SYNC_FLUSH))
{
s->stream.avail_in = 0;
s->stream.next_in = NULL;
s->stream.avail_out = *decoded_len = 0x800;
- s->stream.next_out = *decoded = emalloc(*decoded_len);
+ s->stream.next_out = (Bytef *) *decoded = emalloc(*decoded_len);
switch (status = inflate(&s->stream, Z_SYNC_FLUSH))
{
int status;
/* deflate remaining input */
- s->stream.next_in = PHPSTR_VAL(s->stream.opaque);
+ s->stream.next_in = (Bytef *) PHPSTR_VAL(s->stream.opaque);
s->stream.avail_in = PHPSTR_LEN(s->stream.opaque);
s->stream.avail_out = *encoded_len = 0x800;
- s->stream.next_out = *encoded = emalloc(*encoded_len);
+ s->stream.next_out = (Bytef *) *encoded = emalloc(*encoded_len);
do {
status = deflate(&s->stream, Z_FINISH);
int status;
/* inflate remaining input */
- s->stream.next_in = PHPSTR_VAL(s->stream.opaque);
+ s->stream.next_in = (Bytef *) PHPSTR_VAL(s->stream.opaque);
s->stream.avail_in = PHPSTR_LEN(s->stream.opaque);
s->stream.avail_out = *decoded_len = s->stream.avail_in << 2;
- s->stream.next_out = *decoded = emalloc(*decoded_len);
+ s->stream.next_out = (Bytef *) *decoded = emalloc(*decoded_len);
if (Z_STREAM_END == (status = inflate(&s->stream, Z_FINISH))) {
/* cut processed input off */
PHPSTR_API size_t phpstr_resize_ex(phpstr *buf, size_t len, size_t override_size)
{
+#if 0
+ fprintf(stderr, "RESIZE: size=%lu, used=%lu, free=%lu\n", buf->size, buf->used, buf->free);
+#endif
if (buf->free < len) {
size_t size = override_size ? override_size : buf->size;
return 0;
}
+PHPSTR_API size_t phpstr_shrink(phpstr *buf)
+{
+ /* avoid another realloc on fixation */
+ if (buf->free > 1) {
+ char *ptr = perealloc(buf->data, buf->used + 1, buf->pmem);
+
+ if (ptr) {
+ buf->data = ptr;
+ } else {
+ return NOMEM;
+ }
+ buf->free = 1;
+ }
+ return buf->used;
+}
+
PHPSTR_API size_t phpstr_append(phpstr *buf, const char *append, size_t append_len)
{
if (NOMEM == phpstr_resize(buf, append_len)) {
#define phpstr_resize(b, s) phpstr_resize_ex((b), (s), 0)
PHPSTR_API size_t phpstr_resize_ex(phpstr *buf, size_t len, size_t override_size);
+/* shrink memory chunk to actually used size (+1) */
+PHPSTR_API size_t phpstr_shrink(phpstr *buf);
+
/* append data to the phpstr */
#define phpstr_appends(b, a) phpstr_append((b), (a), sizeof(a)-1)
#define phpstr_appendl(b, a) phpstr_append((b), (a), strlen(a))
$f = fopen($n, 'wb');
stream_filter_append($f, 'http.deflate', STREAM_FILTER_WRITE, HTTP_DEFLATE_TYPE_GZIP);
fwrite($f, $d);
+fflush($f);
+fwrite($f, $d);
fclose($f);
-var_dump($d == http_inflate(file_get_contents($n)));
+var_dump($d.$d == http_inflate(file_get_contents($n)));
$f = fopen($n, 'wb');
stream_filter_append($f, 'http.deflate', STREAM_FILTER_WRITE);
fwrite($f, $d);
+fflush($f);
+fwrite($f, $d);
fclose($f);
-var_dump($d == http_inflate(file_get_contents($n)));
+var_dump($d.$d == http_inflate(file_get_contents($n)));
$f = fopen($n, 'wb');
stream_filter_append($f, 'http.deflate', STREAM_FILTER_WRITE, HTTP_DEFLATE_TYPE_RAW);
fwrite($f, $d);
+fflush($f);
+fwrite($f, $d);
fclose($f);
-var_dump($d == http_inflate(file_get_contents($n)));
+var_dump($d.$d == http_inflate(file_get_contents($n)));
unlink($n);