Is there any way to work with a .gz file directly?
I have a compressed text file that is 300M compressed, and over 8G uncompressed. I'd like to be able to work with the file in it's compressed mode.
Any hints?
-t
Yes, you can work directly with .gz compressed files: http://www.php.net/manual/en/ref.zlib.php
You'll need to recompile PHP with the zlib functions however. But the library works much like the filesystem functions: $gf = gzopen($file,'r+'); $data = gzread($gf, 1200); gzclose($gf);
Note: working with Gz files does not mean you're actually working with the compressed data, it will probably have to uncompress the file in order to be able to read it, so you may still need 8GB of memory-space in order to read the file.
very true. In fact it transparently compresses and decompresses the data for you.
Which is why I set the gzread() to only 1200 bytes.
But that notice is prominantly posted in the man pages... but then again, most people never bother to read them.
Thanks for the pointer. My initial search at php.net was not successful - apparently searching the "Whole Site" and the "Online Documentation" for "gz" was not enough. I did not think to search the function list...
This is just what I was looking for. Thanks.