New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read from a gzip'ed input file #11

Closed
staabm opened this Issue Dec 13, 2015 · 1 comment

Comments

Projects
None yet
2 participants
@staabm

staabm commented Dec 13, 2015

the readme mentioned "read from a gzip'ed input file", do you have any example how the code look like for it?

I would like to read a GZIPPED resource via url in my stream.

with the regular php filter functions one often gets a "stream_filter_append(): Filter failed to process pre-buffered data" error, because the inflate filter cannot work the the additional gzip header.

If this lib is aimed for ease of use, I would expect that it bundles a mechanism which allows to read gzipped content.

Atm I am using

$url = 'http://localhost/dev/fileget_zlib/packages.json';
$fp = fopen($url, 'r', null, $ctx);
Filter\append($fp, 'zlib.inflate');
echo stream_get_contents($fp);

which triggers a exception:
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'No valid callback parameter given to stream_filter_(append|prepend)'

thanks for the great lib.

@clue clue added the question label Mar 2, 2016

@clue

This comment has been minimized.

Owner

clue commented Mar 2, 2016

Thanks for the good question @staabm!

with the regular php filter functions one often gets a "stream_filter_append(): Filter failed to process pre-buffered data" error, because the inflate filter cannot work the the additional gzip header.

The zlib.* stream filters assume the ZLIB format (RFC 1950) by default, while you're trying to consume GZIP format (RFC 1952). See also clue/reactphp-zlib#3 (comment) and https://twitter.com/JoelWurtz/status/664900933889970176.

As such, using this library doesn't really help much as this can be achieved via PHP's built-in zlib filters:

stream_filter_append($fp, 'zlib.deflate', array('window' => 15|16));

the readme mentioned "read from a gzip'ed input file", do you have any example how the code look like for it? […] If this lib is aimed for ease of use, I would expect that it bundles a mechanism which allows to read gzipped content.

I understand where you're coming from, the README could certainly use a better wording. The referenced text from the README was meant to be an example of what can be achieved via PHP's stream filters, not necessarily what this library can help with.

The zlib filter is one of many available filters and as such this library does not provide any special support for it. Admittedly, one of the key motivations for building this library was exposing the zlib filter. For this reason, I've also built https://github.com/clue/php-zlib-react on top of this library, so perhaps this may help?

If you feel like updating the README to make this information more obvious, I'd be happy to get this in 👍

I hope this helps!

@clue clue closed this Mar 2, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment