stream filters (php5)

From: Date: Sun, 06 Feb 2005 09:02:48 +0000
Subject: stream filters (php5)
Groups: php.general 
Request: Send a blank email to php-general+get-208140@lists.php.net to get a copy of this message
Hi all, This question is based on the given example at http://php.net/manual/en/function.stream-filter-register.php Does anyone have an example of how to implement stream filters that produce their output until all input has been read? For instance, a stream version of md5() which -on every invocation - takes a 4K buffer from input and keeps the current state in a private variable, until EOF. The filter class would look like this: class md5_filter extends php_user_filter { // keep state info here private $buf=''; function filter($in, $out, &$consumed, $closing) {
       while ($bucket = stream_bucket_make_writeable($in)) {
           $this->buf .= $bucket->data; // build state data (in a more sensible way than this!)
           $consumed += $bucket->datalen;
       }
       // no more buckets from bucket input brigage
       if ($closing) {
           // all input has been read at this point, so make new bucket??
           $bucket = stream_bucket_new(??,md5($this->buf));
           // and append it to the output bucket brigade
           stream_bucket_append($out,$bucket);
           return PSFS_PASS_ON;
       }
       return PSFS_FEED_ME;
} } EOF is signalled by the $closing parameter in the filter() method. After that, one would need to create a bucket to use on stream_bucket_append(). Any ideas? Kind regards, Jack

« previous php.general (#208140) next »