How can I split (copy) a Stream in .NET?

后端 未结 7 2314
北荒
北荒 2020-12-03 11:59

Does anyone know where I can find a Stream splitter implementation?

I\'m looking to take a Stream, and obtain two separate streams that can be independently read a

7条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-03 12:26

    Not out of the box.

    You'll need to buffer the data from the original stream in a FIFO manner, discarding only data which has been read by all "reader" streams.

    I'd use:

    • A "management" object holding some sort of queue of byte[] holding the chunks to be buffered and reading additional data from the source stream if required
    • Some "reader" instances which known where and on what buffer they are reading, and which request the next chunk from the "management" and notify it when they don't use a chunk anymore, so that it may be removed from the queue

提交回复
热议问题