function gen_row($row) { rewind($this->outstream); // rewind the memory stream $len = parent::gen_row($row); rewind($this->outstream); // rewind the memory stream $csvstr = stream_get_contents($this->outstream); // read csv from the memory stream $ret = bzwrite($this->bz2stream, $csvstr, $len); // write csv from the bzip2 stream }