mpen
mpen

Reputation: 283355

Stream inflate wrapper?

In PHP you can open a gzipped resource either like this:

$fp = fopen('compress.zlib://http://httpbin.org/gzip','rb')

or

$fp = gzopen('http://httpbin.org/gzip','rb')

How can I open a deflated resource? (such as http://httpbin.org/deflate)

N.B. I do not want to read the entire stream into memory so that I can run gzinflate on it.

Upvotes: 1

Views: 151

Answers (2)

FuzzyTree
FuzzyTree

Reputation: 32402

You can use stream_filter_append to apply an inflation filter on read.

$fp = fopen('http://httpbin.org/deflate','rb');
$params = array('level' => 6, 'window' => 15, 'memory' => 9);
stream_filter_append($fp, 'zlib.inflate', STREAM_FILTER_READ, $params);
print fread($fp,8192);

Upvotes: 1

blue112
blue112

Reputation: 56602

As mentioned here, you can use the mode argument of gzopen to precise the compression mode.

Upvotes: 0

Related Questions