Read a buffer at a time and pass it to the two consumers. There's nothing in your question that would prevent this simple solution from being used. That would look like this:
while(dataAvailable) {
var buffer = Read();
Write1(buffer);
Write2(buffer);
}
You can also play with wrapper streams that perform a side-effect (such as hashing) and just pass on the buffer to the next stream.
It becomes more complicated if you have multiple pieces of code requiring reads from a stream (such as two independent XmlReader
's). In that case you need to demultiplex. You probably need to keep a buffer of data and only when all consumers have read that buffer you load the next buffer. This would involve threading and synchronization because multiple independent readers need to read in lock-step.