I have read this question/answer: How do I copy the contents of one stream to another?.
And I've read the doc pages of Stream.CopyToAsync
and Stream.CopyTo
.
I haven't found anything in any of them which either:
- Tells me how to achieve this.
- Confirms whether those methods do this automatically.
So it's possible that the answer is "yes, just use those methods", but that's not something that I can see documented on any of those...
- I have an existing Stream object (A).
- I have an async void method
PopulateStream()
which is going to write data into that stream. - I want to create a new Stream object (B), and I want the data from above to be written onto that Stream.
- I don't want to wait for all the data to have been written to A before it starts being written to B.
- i.e. I want the data to "Stream" from one Stream object to the other, as it is written.
- I don't have any control over the creation of Stream A, though I do have a reference to it.
- I don't have any control over the body of
PopulateStream()
Without point 4. I could just await PopulateStream()
, and the use the copy methods.
Can I just call the copy method before I await PopulateStream()
? Will that copy future data added to Stream A? Or will it only copy the data that's currently there (which in this case would be ... nothing, yet.
If I can do this, then do I need to do anything to Stream B after PopulateStream()
completes, to indicate that all the data has been written? Presumably something in PopulateStream()
already does that for Stream A?