In some circumstances, you may want to send a bzip2 stream to the client.
To do this, you need only do:
$bz = bzopen('php://stdout', 'w');
bzwrite($bz, 'some input here');
However, please note, because you are using STDOUT, you need to ob_flush() before actually writing to the stream. Otherwise, you might be sending data before the headers, which will cause errors on both server and client ends, in most cases.
You might be able to use php://output rather than php://stdout, however in my tests (with Linux), php://output doesn't actually work - at all.
(PHP 4 >= 4.0.4, PHP 5)
bzopen — Opens a bzip2 compressed file
bzopen() opens a bzip2 (.bz2) file for reading or writing.
The name of the file to open.
Similar to the fopen() function, only 'r' (read) and 'w' (write) are supported. Everything else will cause bzopen to return
If the open fails, bzopen() returns
it returns a pointer to the newly opened file.
Example #1 bzopen() example
$file = "/tmp/foo.bz2";
$bz = bzopen($file, "r") or die("Couldn't open $file for reading");
- bzclose() - Close a bzip2 file
the example show above is _not_ working in every case!
This example will continue reading until there is no more data: