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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to