One-liners to gzip and ungzip a file:
copy('file.txt', 'compress.zlib://' . 'file.txt.gz');
copy('compress.zlib://' . 'file.txt.gz', 'file.txt');
zlib:// -- bzip2:// -- zip:// — Compression Streams
compress.zlib:// and compress.bzip2://
zlib: works like gzopen(), except that the stream can be used with fread() and the other filesystem functions. This is deprecated due to ambiguities with filenames containing ':' characters; use compress.zlib:// instead.
compress.zlib:// and compress.bzip2:// are equivalent to gzopen() and bzopen() respectively, and operate even on systems that do not support fopencookie.
ZIP extension registers zip: wrapper. As of
PHP 7.2.0 and libzip 1.2.0+, support for the passwords for encrypted archives were added, allowing
passwords to be supplied by stream contexts. Passwords can be set using the 'password'
stream context option.
One-liners to gzip and ungzip a file:
copy('file.txt', 'compress.zlib://' . 'file.txt.gz');
copy('compress.zlib://' . 'file.txt.gz', 'file.txt');
Example on how to read an entry from a ZIP archive (file "bar.txt" inside "./foo.zip"):
<?php
$fp = fopen('zip://./foo.zip#bar.txt', 'r');
if( $fp ){
while( !feof($fp) ){
echo fread($fp, 8192);
}
fclose($fp);
}
?>
Also, apparently, the "zip:" wrapper does not allow writing as of PHP/5.3.6. You can read http://php.net/ziparchive-getstream for further reference since the underlying code is probably the same.