If you are designing an API, or even within your own code, and your method accepts a Stream
, is it your method's duty to check the position and reset it to the beginning provided that CanSeek
is true
before using it?
If so, why isn't there a method that does all this on the Stream
class itself?
Over the years I've been caught out a few times by assuming the Stream
comes into my method in position 0.
And is it right to reset the Stream
where possible after using it?
Alternatively, should Stream
s always be copied around instead of passed around directly? Seems a bit excessive to me.
is it your method's duty to check the position and reset it to the beginning provided that CanSeek is true before using it?
No, in that case I would expect the calling code to prepare the stream correctly.
The most common patterns that share a stream over methods require that the pointer is left exactly after the last read/write, so this never comes up much.
But the best thing to after using it: do nothing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With