Setting output stream to multiple streams


I need to send the output from a request down two different streams:
how can I do this? How can I build a stream stack and tell the lib
that the output should flow throw the stack?

Just in case this isn't clear, let me explain what I am trying to do:
I want to keep a copy of the fetched document in a buffer AND write a
copy to a file.

Any help most apprecaited,