I have a bigfile.gz.gz file that is ... big. I would like to unzip it on the fly. Ideally, this is what I mean:
$in = fopen('compress.zlib://compress.zlib://bigfile.gz.gz', 'rb'); while (!feof($in)) print fread($in, 4096); fclose($in);
However, compress.zlib:// cannot be bound this way:
PHP Warning: fopen(): cannot represent a stream of type ZLIB as a File Descriptor in gztest.php on line 1
So, I thought Id combines gzopen() and compress.zlib:// together:
$in = gzopen('compress.zlib://bigfile.gz.gz', 'rb'); while (!gzeof($in)) print gzread($in, 4096); gzclose($in);
However, this only decompresses one gzip level.
I probably tried 10 more other methods, unfortunately gzopen() does not work with php://memory if it was written using fwrite() . And stream_filter_append(β¦ zlib.inflate β¦) cannot read gzipped files.
This is the best I could come up with, but it spawns two system processes that have unwanted overhead:
$in = popen('zcat bigfile.gz.gz | gunzip', 'rb'); while (!feof($in)) print fread($in, 4096); fclose($in);
Can someone suggest something better maybe?
php gzip zlib
sam hocevar
source share