Hello.

Just learning about stream filtering and have 2 questions I hope
someone can give me some pointers on.


1 - Bucketing.

In reading a bit about how this works, the data is passed in chunks
through the filter - known as a bucket brigade.

How does this work if, for example, the search string is chopped by
the bucketing system? It would seem that you would end up with 2 parts
of the search element, neither would be matched for replacing and then
the whole element would be reconstituted in the output.

My filter method is ...

        function filter($r_In, $r_Out, &$i_Consumed, $b_Closing)
                {
                while ($o_Bucket = stream_bucket_make_writeable($r_In))
                        {
                        $o_Bucket->data = preg_replace('`<(/?)(\d+)`', 
'<$1fixed_$2',
$o_Bucket->data);
                        $i_Consumed += $o_Bucket->datalen;
                        stream_bucket_append($r_Out, $o_Bucket);
                        }

                return PSFS_PASS_ON;
                }

This is working fine (so far as I can tell as SimpleXMLIterator is now
happy to read the XML file), but I'm guessing I'm missing something
here if my understanding is correct.




2 - Stream wrapping.

At the moment, we download a .gz file and decompress it into the .xml
file. I know I can use a zlib:// stream wrapper to save me having to
decode the .gz file first. This means smaller downloads and less
storage. We can even use the zlib:// filter on the URL, but we cache
the .gz file locally, so that isn't important.

But for a small set of files (their origin is known, so I can create a
rule for this issue), I have to expand the .gz file first and then fix
the file using the filter above. I then have two paths to load the xml
- either a zlib:// decompress stream or a straight local file.

I'd like to work out how to create a stream wrapper to allow me to say
SOMETHING like ...

$o_MySXI = new 
SimpleXMLIterator('xml.NoNumericTags://compress.zlib:///development/BadlyFormed.gz');

If this was possible, I'd be a LOT happier and could simply stream
from the .gz files without needing to hold onto anything.


Ideas/suggestions/examples/code gratefully received.

Regards,

Richard.

-- 
Richard Quadling
Twitter : EE : Zend : Fantasy Shopper
@RQuadling : http://e-e.com/M_248814.html : http://bit.ly/9O8vFY :
http://fan.sh/106/5tw

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

Reply via email to